-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (28 loc) · 27.8 KB
/
index.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
const express = require('express');
const app = express();
const router = express.Router();
const mongoose = require('mongoose');
const config = require('./config/database');
const path = require('path');
const authentication = require('./routes/authentication')(router);
const bodyParser = require('body-parser');
const cors = require('cors');
mongoose.Promise = global.Promise;
mongoose.connect(config.uri, (err)=> {
if (err){
console.log('Could not connect to database: ', err);
} else{
console.log('Connected to database: ' + config.db);
}
});
app.use(cors({origin: 'http://localhost:4200'}));
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.use(express.static(__dirname + '/client/dist/'));
app.use('/authentication', authentication);
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/client/dist/index.html'));
});
app.listen(8080, () => {
console.log('Listening on port 8080');
});