-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (52 loc) · 1.54 KB
/
index.js
File metadata and controls
63 lines (52 loc) · 1.54 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const express = require("express");
const path = require("path");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const static = require("./routes/static");
const favicon = require("serve-favicon")
const api = require("./routes/api");
const app = express();
app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(favicon(path.join(__dirname, "assets/img", "favicon.ico")))
const dotenv = require("dotenv");
if (process.env.NODE_ENV != "test") {
//Connessione Moongose
require("./db").connect();
dotenv.config({
path: ".env",
});
} else {
dotenv.config({
path: ".env.example",
});
}
const port = process.env.NODE_PORT || 8080;
if (!process.env.DOCKER) {
console.log('Not running in docker, you should use: "docker-compose up"\n');
}
app.use(express.static(path.join(__dirname, "assets")));
app.use(static);
module.exports = app;
app.use(function (req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Methods",
"GET, POST, OPTIONS, PUT, PATCH, DELETE"
);
res.setHeader(
"Access-Control-Allow-Headers",
"X-Requested-With,content-type"
);
res.setHeader("Access-Control-Allow-Credentials", true);
next();
});
app.use("/api", api);
app.listen(port, () => {
console.log(
`Node Server listening on port ${port}\n\n` +
(process.env.DOCKER ? "https://localhost" : `http://localhost:${port}`)
);
});