-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
40 lines (31 loc) · 1.03 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
const express = require("express");
const path = require("path");
const bodyParser = require("body-parser");
require('dotenv').config();
const PORT = process.env.PORT || 3001;
const app = express();
const apiRoutes = require("./routes/apiRoutes");
const mongoose = require("mongoose");
app.use(express.static("client/build"));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use("/api", apiRoutes);
app.get("*", function(req, res) {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
mongoose.Promise = global.Promise;
mongoose.connect(
process.env.MONGODB_URI || "mongodb://localhost/launchboxdb",
{
useMongoClient: true
}
);
app.listen(PORT, function() {
console.log(`🌎 ==> Server now on port ${PORT}!`);
});