-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
57 lines (53 loc) · 1.42 KB
/
server.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
45
46
47
48
49
50
51
52
53
54
55
56
57
const express = require("express");
const cors = require("cors");
const path = require("path");
// const expressLogger = require("express-bunyan-logger");
const routes = require("./routes");
require("./db");
const app = express();
// app.use(
// expressLogger({
// excludes: [
// "headers",
// "req",
// "user-agent",
// "short-body",
// "http-version",
// "req-headers",
// "res-headers",
// "body",
// "res",
// ], // remove extra details from log
// })
// );
app.use(cors());
app.use(express.json());
app.use(express.static(path.join(__dirname, "public")));
app.use("/", routes);
//========================================================================================================================
// catch 404 and forward to error handler
app.all("*", (req, res, next) => {
next({
message: `can't find ${req.originalUrl} on this server.`,
status: 404,
});
});
// development error handler
// will print stacktrace
app.use(function (err, req, res, next) {
// log.error(err);
res.status(err.status || 500).send({
success: err.success || false,
message: err.message || "Something went wrong",
error: err,
});
});
const PORT = process.env.PORT || 8080;
app.listen(
PORT,
console.log("Express server listening on http://localhost:%d", PORT)
);
// log.info(
// "Express server listening on http://localhost:%d",
// server.address().port
// );