-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (23 loc) · 976 Bytes
/
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 securer = require('./middlewares/securer.middleware');
const errorMiddleware = require('./middlewares/error.middleware');
const router = require('./router/app.router');
require('dotenv').config()
const port = process.env.PORT || 8080;
const server = express();
server.use(express.json());
server.use(express.urlencoded({extended:true}))
server.use(securer);
server.use('/', express.static('public'));
server.use('/', router);
server.use(errorMiddleware);
server.listen(port)
.on('listening', () => {
console.log(`--> listening port ${port}.`)
if( process.env.DATASOURCE === 'mongo' ) {
const Mongo = require('./models/containers/mongo.container')
Mongo.connect().then( () => console.log('--> connected to MongoDB.') )
}
})
.on('request', (data) => console.log(`--> new ${data.method} request to ${data.url}` ) )
.on('error', (err) => console.log(`--> ${err}`) )