-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathweb.js
44 lines (36 loc) · 952 Bytes
/
web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Copyright (c) 2016-2017 DrSmugleaf
//
"use strict"
const DB = require("./src/util/db")
const db = new DB()
const express = require("express")
const logger = require("morgan")
const winston = require("winston")
const app = express()
app.set("port", (process.env.PORT || 5000))
app.use(logger("dev"))
app.use(express.static(__dirname + "/web/public"))
app.set("views", __dirname + "/web/views")
app.set("view engine", "ejs")
app.use(function(req, res, next) {
winston.info("/" + req.method)
next()
})
app.get("/", function(req, res) {
res.render("pages/index")
})
app.get("/quotes", function(req, res) {
db.query("SELECT * FROM quotes").then(data => {
res.render("pages/quotes", { results: data })
}).catch(e => {
winston.error(e)
res.send("Error")
})
})
app.use("*", function(req, res) {
res.render("pages/404")
})
app.listen(process.env.PORT || 3000, function() {
winston.info(`Live at ${app.get("port")}`)
})