-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
52 lines (43 loc) · 1.39 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
const express = require("express");
const bodyParser = require("body-parser");
const cookieParser = require('cookie-parser');
const path = require('path');
const htmlRoutes = require('./routes/htmlRoutes.js');
const apiRoutes = require('./routes/apiRoutes.js');
const morgan = require('morgan');
const bluebird = require("bluebird");
const mongoose = require("mongoose");
const expressFileUpload = require('express-fileupload');
const Server = {
port : 3001,
app : express(),
}
Server.app.use(bodyParser.urlencoded({ extended: true }));
Server.app.use(bodyParser.json());
Server.app.use(expressFileUpload());
Server.app.use(cookieParser());
Server.app.use(morgan('dev'));
Server.app.use(htmlRoutes);
Server.app.use(apiRoutes);
if (process.env.NODE_ENV === "production") {
Server.app.use(express.static("client/build"));
} else {
Server.app.use(express.static(__dirname + "/client/public"));
}
Server.app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
/*const db = process.env.MONGODB_URI || "mongodb://localhost/project-3-amico";
mongoose.connect(db, err => {
if (err) {
console.log("Mongo db error: ", err);
} else {
console.log("Mongo db is now connected!");
}
});*/
Server.app.listen(process.env.PORT || Server.port);