forked from imar26/webdevangular4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (30 loc) · 1.14 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
// Get the dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Point static path to dist -- For building -- REMOVE
app.use(express.static(path.join(__dirname, 'dist')));
// CORS
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
next();
});
const port = process.env.PORT || '3100';
app.set('port', port);
// Create HTTP server
const server = http.createServer(app);
// var serverSide = require("./server/test-mongodb/app");
// serverSide(app);
// require('./todo/app')(app);
require('./assignment/app')(app);
// For Build: Catch all other routes and return the index file -- BUILDING
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
server.listen( port , () => console.log('Running'));