forked from libreflix/libreflix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·135 lines (112 loc) · 3.57 KB
/
server.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
var express = require('express');
var path = require('path');
var logger = require('morgan');
var compression = require('compression');
var methodOverride = require('method-override');
var session = require('express-session');
var flash = require('express-flash');
var bodyParser = require('body-parser');
var expressValidator = require('express-validator');
var dotenv = require('dotenv');
var nunjucks = require('nunjucks');
var markdown = require('nunjucks-markdown');
var marked = require('marked');
var mongoose = require('mongoose');
var elasticsearch = require('elasticsearch');
var passport = require('passport');
var routes = require('./routes');
var processImage = require('express-processimage');
var i18n = require("i18n");
var cookieParser = require('cookie-parser');
var minifyHTML = require('express-minify-html');
var device = require('express-device');
const pjson = require('./package.json');
// Load environment variables from .env file
dotenv.load();
// Passport OAuth strategies
require('./config/passport');
var app = express()
app.use(cookieParser())
app.use(device.capture())
mongoose.connect(process.env.DB_PATH);
mongoose.set('debug', false);
mongoose.connection.on('error', function() {
console.log('MongoDB Connection Error. Please make sure that MongoDB is running.');
process.exit(1);
});
// view engine setup
var njks = nunjucks.configure('views', {
autoescape: true,
express: app,
marked: true
});
markdown.register(njks, marked);
// i18n options
i18n.configure({
locales:['pt', 'en', 'es'],
defaultLocale: 'pt',
queryParameter: 'lang',
cookie: 'siteLang',
directoryPermissions: '775',
autoReload: true,
updateFiles: false,
directory: __dirname + '/public/locales',
api: {
'__': 't', //now req.__ becomes req.t
}
});
app.use(i18n.init);
/* Minify options */
// app.use(minifyHTML({
// override: true,
// exception_url: true,
// htmlMinifier: {
// removeComments: false,
// collapseWhitespace: false,
// collapseBooleanAttributes: false,
// removeAttributeQuotes: false,
// removeEmptyAttributes: false,
// minifyJS: true
// }
// }));
app.set('view engine', 'html');
app.set('port', process.env.PORT || 3998);
app.use(compression());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(expressValidator());
app.use(methodOverride('_method'));
app.use(session({ secret: process.env.SESSION_SECRET, resave: true, saveUninitialized: true }));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(function(req, res, next) {
res.locals.user = req.user;
res.locals.baseurl = process.env.BASEURL;
res.locals.appVersion = pjson.version;
next();
});
/*
* https://www.npmjs.com/package/express-processimage
* pacote de thumb pra corrigir o issue: https://libregit.org/libreflix/libreflix/issues/19
* instrução pra recortar uma imagem https://github.com/papandreou/express-processimage/issues/14
*/
app.use(processImage(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
/**
* Setup Routes
*/
routes.init(app, passport);
uploadDir = path.join(__dirname, '/public/media/');
// Production error handler
if (app.get('env') === 'production') {
app.use(function(err, req, res, next) {
console.error(err.stack);
res.sendStatus(err.status || 500);
});
}
app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});
module.exports = app;