123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- const express = require('express');
- const path = require('path');
- const favicon = require('serve-favicon');
- const logger = require('morgan');
- const cookieParser = require('cookie-parser');
- const bodyParser = require('body-parser');
- const i18n = require("i18n");
- const config = require('./config');
- const routes = require('./routes/index');
- const app = express();
- i18n.configure({
- defaultLocale: "en",
- directory: __dirname + '/locales',
- autoReload: true
- });
- i18n.setLocale(config.locale);
- app.use(i18n.init);
- 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: false }));
- app.use(cookieParser());
- app.use(express.static(path.join(__dirname, 'public')));
- app.use(config.subpath, routes);
- app.use(function(req, res, next) {
- const err = new Error('Not Found');
- err.status = 404;
- next(err);
- });
- if (app.get('env') === 'development') {
- app.use(function(err, req, res, next) {
- res.status(err.status || 500);
- res.render('error', {
- message: err.message,
- error: err
- });
- });
- }
- app.use(function(err, req, res, next) {
- res.status(err.status || 500);
- res.render('error', {
- message: err.message,
- error: {}
- });
- });
- module.exports = app;
|