-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (30 loc) · 993 Bytes
/
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
const express = require('express');
const http = require('http');
const path = require('path');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
//API file for interacting with MongoDB
const api = require('./server/routes/api');
//configure cors
// var corsOptions = {
// origin: ["http://localhost:4200","http://localhost:4200/register"],
// optionsSuccessStatus: 200
// }
app.use(cors());
//Parsers
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
// Angular DIST output folder
app.use(express.static(path.join(__dirname, 'dist')));
//API location
app.use('/api',api);
//Send all other requests to the Angular App
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname,'dist/index.html'));
});
//Set port
const port = process.env.PORT || '3001';
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log(`Server running on localhost:${port}`));