-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (35 loc) · 1.07 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const config = require('./config/database');
const path = require('path');
const router = express.Router();
const authentication = require('./routes/authentication')(router);
const event = require('./routes/event')(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 be connected database");
}else{
console.log("database connected " +config.db);
}
}
);
app.use(cors({
origin: 'http://localhost:4200'
}));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.use(express.static(__dirname+'/client/dist'));
app.use('/api', authentication);
app.use('/api', event);
app.get('/', function(req, res) {
res.sendfile(path.join(__dirname +'/client/dist/index.html'));
});
app.listen(8080, function() {
console.log('App listening on port 8080');
});