This repository was archived by the owner on May 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (43 loc) · 1.44 KB
/
server.js
File metadata and controls
46 lines (43 loc) · 1.44 KB
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
require("rootpath")();
const express = require("express");
const app = express();
const cors = require("cors");
const bodyParser = require("body-parser");
const compression = require("compression");
const helmet = require("helmet");
const jwt = require("src/helpers/jwt");
const errorHandler = require("src/helpers/error-handler");
const morgan = require("morgan");
const winston = require("config/winston");
const config = require("config.json");
const path = require("path");
app.use(express.static(path.join(__dirname, config.pathToBuild)));
app.use(helmet());
app.use(morgan("combined", {
skip: function (req, res) {
return res.statusCode < 400
},
stream: winston.stream
}));
app.use(bodyParser.urlencoded({
extended: true,
limit: "10mb"
}));
app.use(bodyParser.json({
limit: "10mb"
}));
app.use(cors());
app.get(/^\/(?!api).*/, (req, res) => {
res.sendFile(path.join(__dirname + `/${config.pathToBuild}/index.html`));
});
app.use(jwt());
app.use("/api/users", require("src/users/user.controller"));
app.use("/api/drawings", require("src/drawings/drawing.controller"));
app.use("/api/password", require("src/forgot-pass/forgot-pass.controller"));
app.use(compression());
app.use(errorHandler);
// both 4000, nginx will handle the request through the reverse proxy
const port = process.env.NODE_ENV === "production" ? 4000 : 4000;
const server = app.listen(port, function () {
winston.info(`Server listening on port : ${port}`);
});