-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
47 lines (36 loc) · 1.25 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
const express = require('express');
const bodyParser = require('body-parser');
const path = require("path")
// create express app
const app = express();
var cors = require("cors");
app.use(cors());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }))
// parse requests of content-type - application/json
app.use(bodyParser.json())
app.use(express.static(path.join(__dirname, "react", "sur-way-app", "build")))
// Configuring the database
const dbConfig = require('./config/database.config.js');
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
// Connecting to the database
mongoose.connect(dbConfig.url, {
useNewUrlParser: true
}).then(() => {
console.log("Successfully connected to the database");
}).catch(err => {
console.log('Could not connect to the database. Exiting now...', err);
process.exit();
});
var api_router = require('./app/router');
app.use(api_router)
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "react", "sur-way-app", "build", "index.html"));
});
require("dotenv").config()
const port = process.env.PORT || 5000;
// listen for requests
app.listen(port, () => {
console.log("Server is listening on port 3000");
});