-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
44 lines (35 loc) · 973 Bytes
/
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
var express = require('express'),
path = require('path'),
logger = require('morgan'),
serveStatic = require('serve-static'),
bodyParser = require('body-parser'),
fs = require('fs'),
app = express(),
tmpFolder = path.join(__dirname, 'tmp'),
debug = require('debug')('node-express-subtitulos-es');
// creating tmp folder if not exists
if (!fs.existsSync(tmpFolder)) {
fs.mkdir(tmpFolder);
}
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(serveStatic(path.join(__dirname, 'public')));
//Injection of global variables
app.use(function(req, res, next) {
res.locals.tmpFolder = tmpFolder;
next();
});
//Router declaration
var router = require('./router');
app.use('/', router);
/// catch * and forwards to home
app.use(function(req, res, next) {
res.redirect('/');
});
module.exports = app;