-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
75 lines (55 loc) · 2.86 KB
/
server.ts
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
///<reference path='./typings/main.d.ts' />
"use strict";
import * as express from "express";
import * as path from "path";
import {logger,loggerStream,database} from "./util";
import {config} from "./config";
import * as Promise from "bluebird";
import * as morgan from "morgan";
import * as templates from "nunjucks";
import {router as sprintRouter} from "./router-sprint";
import {router as sprintRestRouter} from "./router-rest-sprint";
const moment = require("moment");
moment.locale("es");
export const app = express();
/**********************************************************************************************************************
* Logger
**********************************************************************************************************************/
logger.debug("Overriding 'Express' logger");
app.use(morgan("combined",{ "stream": loggerStream }));
/**********************************************************************************************************************
* Se conecta a la base de datos
**********************************************************************************************************************/
if(process.env.NODE_ENV == "production") {
database.connect(config.database.prod);
}
else {
database.connect(config.database.dev);
}
/**********************************************************************************************************************
* Configura el motor de vista
**********************************************************************************************************************/
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'twig');
app.locals.basedir = app.get('views');
//--- Habilita moment para que esté disponible por defecto en las plantillas
app.locals.moment = moment;
templates.configure('views', {
autoescape: false,
express: app,
watch: true
});
/**********************************************************************************************************************
* Configuración de rutas
**********************************************************************************************************************/
app.use('/node_modules', express.static(path.join(__dirname,'../node_modules')));
app.use(express.static('public'));
app.use('/public-react', express.static(path.join(__dirname,'../public-react')));
app.use("/sprint",sprintRouter);
app.use("/rest/sprint",sprintRestRouter);
/**********************************************************************************************************************
* Servidor
**********************************************************************************************************************/
app.listen(process.env.NODE_PORT || 3000, () => {
logger.info(`Sauron 2.0 server arrancado en el puerto ${process.env.NODE_PORT || 3000} en modo: ${!process.env.NODE_ENV?'DEVELOPMENT':process.env.NODE_ENV.toUpperCase()}`);
});