-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
70 lines (53 loc) · 2.17 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
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
const express = require("express");
const http = require("http");
const path = require("path");
const compression = require("compression");
const minify = require("express-minify");
const formidable = require("express-formidable");
const dbManager = require("./server/db/dbmanager.js");
const sConfig = require("./server/config/serverconfig.js");
const routes = require("./server/routes");
const sesionManager = require("./server/sesion/sesionmanager.js");
const live = require("./server/api/live.js");
const cache = require("./server/db/cache.js");
const defaults = require("./server/db/defaults.js");
const threads = require("./server/extra/threads.js");
/* SETUP INICIAL */
var app = express();
var server = http.createServer(app);
/* MIDDLEWARES */
//compresion y minificar
app.use(compression());
//carpeta del node.
//TODO: sacar esto de aca.
app.use('/node', express.static(path.join(__dirname, 'node_modules/')));
//ignorar la carpeta del node.
app.use(minify());
//carpeta donde van los archivos estaticos.
app.use('/', express.static(path.join(__dirname, './client/static'), sConfig.STATIC_CACHE_VALUE));
//carpeta de subidas locales..
app.use('/uploads', express.static(path.join(__dirname, './uploads'), sConfig.STATIC_CACHE_VALUE));
//formidable para los post request
app.use(formidable({}, [{event: 'error', action: function (req, res, next, name){console.log("[formidable] Error en el post request.");}}]));
/* VIEW ENGINE (EJS) */
app.set("view engine", "ejs");
app.set('views', path.join(__dirname, './client/views'));
/* BASE DE DATOS */
dbManager.connect(sConfig.DBURL, {useNewUrlParser: true, useUnifiedTopology: true, ssl:sConfig.SSL}, async function (db){
app.locals.db = db;
/* SESION */
let sesion = sesionManager.create(app);
/* CACHE MANAGER */
await cache.init(db);
/* CARGAR DEFAULTS */
await defaults.init(db);
/* WEBSOCKETS (socket.io) */
live.init(server, sesion);
/* RUTAS */
routes(app);
/* THREADS ASINCRONICOS */
threads.init(db);
});
//poner server en escucha en el puerto especificado.
server.listen(sConfig.PORT);
console.log("[Server] Puerto: " + sConfig.PORT + " en escucha.");