-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (26 loc) · 860 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
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const http = require('http');
const app = express();
//API file for interacting with MongoDB
const api = require('./server/routes/api');
const gapi = require('./server/routes/gapi');
//Parsers
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}));
//Angular DIST output folder
app.use(express.static(path.join(__dirname,'dist')));
//API location
app.use('/api',api);
//Send all the other requests to the Angular app
app.use('/*',gapi);
// Home page
app.use('/',(req,res)=>{
res.sendFile(path.join(_dirname,'dist/index.html'));
});
//Set port
const port = process.env.PORT || '3000';
app.set('port', port);
const server = http.createServer(app);
server.listen(port, () => console.log(`Running on localhost:${port}`));