-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
49 lines (41 loc) · 1.2 KB
/
app.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
import bodyParser from "body-parser";
import express from "express";
import http from "http";
import client from "./routes/client.js";
import auth from "./routes/auth.js";
const app = express();
// bodyParser
app.use(bodyParser.json({ limit: "20480KB" }));
app.use(bodyParser.urlencoded({ extended: false, limit: "20480KB" }));
app.use(express.static("public"));
app.use("/", client);
app.use("/auth", auth);
// change the 404 message modifing the middleware
app.use((req, res, next) => {
return res
.status(404)
.send("Sorry, that route doesn't exist. Have a nice day :)");
});
// start the server
const server = http.createServer(app);
const port = 8000;
server.listen(port, "0.0.0.0");
server.on("listening", async () => {
console.log(`Oauth client listening on port: ${port}`);
});
server.on("error", (error) => {
if (error.syscall !== "listen") {
throw error;
}
const bind = typeof port === "string" ? "Pipe " + port : "Port " + port;
switch (error.code) {
case "EACCES":
console.error(bind + " requires elevated privileges");
process.exit(1);
case "EADDRINUSE":
console.error(bind + " is already in use");
process.exit(1);
default:
throw error;
}
});