-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
71 lines (52 loc) · 2.48 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const express = require("express");
const path = require("path");
/**
* some notes about body-parser from express docs:
* body-parser is Node.js body parsing middleware.
* Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
*/
const bodyParser = require("body-parser");
/**
* CORS is a node.js package for providing a Connect/Express middleware that can be used to enable CORS with various options.
*/
const cors = require("cors");
const dotenv = require("dotenv");
const app = express();
const expressWs = require('express-ws');
expressWs(app);
dotenv.config();
/**
* bodyParser.json ===>>
* - Returns middleware that only parses json and only looks at requests where the Content-Type header matches the type option.
* - This parser accepts any Unicode encoding of the body and supports automatic inflation of gzip and deflate encodings.
*
* - A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body).
*/
app.use(bodyParser.json({ limit: "50mb", extended: true }));
/**
* bodyParser.urlencoded ===>>
* Returns middleware that only parses urlencoded bodies and only looks at requests where the Content-Type header matches the type option.
* This parser accepts only UTF-8 encoding of the body and supports automatic inflation of gzip and deflate encodings.
*
* A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body).
* This object will contain key-value pairs, where the value can be a string or array (when extended is false), or any type (when extended is true).
*/
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
// app.use(fileUpload({
// limits: { fileSize: 50 * 1024 * 1024 },
// }));
app.use(cors());
app.use('/api/upload/', require('./routers/upload'));
app.use("/api/user/", require("./routers/user"));
app.use("/api/task/", require("./routers/task"));
app.use("/api/setting/", require("./routers/timerGeneralSetting"));
app.use("/api/template/", require("./routers/template"));
app.use('/api/leaderboard', require('./routers/leaderboard'));
app.use('/api/active', require('./routers/active'));
app.use('/api/stickynote', require('./routers/stickyNotes'));
app.use(express.static(path.join(__dirname, 'build')));
// use "*" for making make the react-router-dom working
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'))
})
module.exports = app;