-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (29 loc) · 1.04 KB
/
app.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
if (!process.env.NODE_ENV){
console.log('Variável de ambiente NODE_ENV não definida');
return process.exit();
}
const express = require('express');
const mongoose = require('mongoose');
const moment = require('moment');
moment.locale('pt-br');
mongoose.Promise = global.Promise;
// TODO: ler de um arquivo ;)
global.SECRET = 'GabrielCampos';
const ioMiddleware = require('./middlewares/ioMiddleware');
const routerMiddleware = require('./middlewares/routerMiddleware');
const graphqlMiddleware = require('./middlewares/graphqlMiddleware');
const app = express();
ioMiddleware.set(app);
routerMiddleware.set(app);
graphqlMiddleware.set(app);
let url;
if (process.env.E_LAPS_MONGO_URL && process.env.E_LAPS_DATABASE){
url = process.env.E_LAPS_MONGO_URL + process.env.E_LAPS_DATABASE;
}else{
url = 'mongodb://127.0.0.1/elaps'
}
mongoose.connect(url);
const porta = process.env.API_E_LAPS_PORT || 5002;
app.listen(porta, ()=>{
console.log('Servidor escutando na porta ' + porta + ' - Data: ' + moment().format('DD/MM/YYYY HH:MM:SS'));
});