mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-02 04:00:36 +00:00
use cookieSession so we can launch in production mode
This commit is contained in:
parent
d70c2c4040
commit
80fd023012
3 changed files with 39 additions and 36 deletions
|
|
@ -1,35 +1,33 @@
|
|||
var nconf = require('nconf');
|
||||
var _ = require('lodash');
|
||||
|
||||
module.exports = function(req, res, next) {
|
||||
|
||||
// show them the splash page if they're not logged in
|
||||
var isStatic = req.url.split('/')[1] == 'static';
|
||||
module.exports.splash = function(req, res, next) {
|
||||
if (req.url == '/' && !req.headers['x-api-user'] && !req.headers['x-api-key'] && !(req.session && req.session.userId))
|
||||
return res.redirect('/static/front')
|
||||
next()
|
||||
};
|
||||
|
||||
res.locals.habitrpg = res.locals.habitrpg || {}
|
||||
_.defaults(res.locals.habitrpg, {
|
||||
NODE_ENV: isStatic ? 'production' : nconf.get('NODE_ENV'), // Don't show debugging options on static pages
|
||||
IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')),
|
||||
STRIPE_PUB_KEY: nconf.get('STRIPE_PUB_KEY')
|
||||
});
|
||||
|
||||
//CORS middleware
|
||||
module.exports.cors = function(req, res, next) {
|
||||
res.header("Access-Control-Allow-Origin", req.headers.origin || "*");
|
||||
res.header("Access-Control-Allow-Methods", "OPTIONS,GET,POST,PUT,HEAD,DELETE");
|
||||
res.header("Access-Control-Allow-Headers", "Content-Type,Accept,Content-Encoding,X-Requested-With,x-api-user,x-api-key");
|
||||
|
||||
if (req.method === 'OPTIONS') {
|
||||
return res.send(200);
|
||||
}
|
||||
/*
|
||||
// translate = (req, res, next) ->
|
||||
// model = req.getModel()
|
||||
// # Set locale to bg on dev
|
||||
// #model.set '_i18n.locale', 'bg' if process.env.NODE_ENV is "development"
|
||||
// next()
|
||||
*/
|
||||
|
||||
if (req.method === 'OPTIONS') return res.send(200);
|
||||
return next();
|
||||
};
|
||||
|
||||
module.exports.locals = function(req, res, next) {
|
||||
res.locals.habitrpg = res.locals.habitrpg || {}
|
||||
_.defaults(res.locals.habitrpg, {
|
||||
NODE_ENV: req.url.split('/')[1] == 'static' ? 'production' : nconf.get('NODE_ENV'), // Don't show debugging options on static pages
|
||||
IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')),
|
||||
STRIPE_PUB_KEY: nconf.get('STRIPE_PUB_KEY')
|
||||
});
|
||||
next()
|
||||
}
|
||||
/*
|
||||
// translate = (req, res, next) ->
|
||||
// model = req.getModel()
|
||||
// # Set locale to bg on dev
|
||||
// #model.set '_i18n.locale', 'bg' if process.env.NODE_ENV is "development"
|
||||
// next()
|
||||
*/
|
||||
|
|
@ -5,6 +5,7 @@ var http = require("http");
|
|||
var path = require("path");
|
||||
var app = express();
|
||||
var nconf = require('nconf');
|
||||
var middleware = require('./middleware');
|
||||
var server;
|
||||
|
||||
// Setup configurations
|
||||
|
|
@ -31,12 +32,16 @@ app.set("views", __dirname + "/../views");
|
|||
app.set("view engine", "jade");
|
||||
app.use(express.favicon());
|
||||
app.use(express.logger("dev"));
|
||||
app.use(middleware.cors);
|
||||
app.use(express.bodyParser());
|
||||
app.use(require('connect-assets')());
|
||||
app.use(express.methodOverride());
|
||||
app.use(express.cookieParser(nconf.get('SESSION_SECRET')));
|
||||
app.use(express.session());
|
||||
app.use(require('./middleware'));
|
||||
//app.use(express.cookieParser(nconf.get('SESSION_SECRET')));
|
||||
app.use(express.cookieParser());
|
||||
app.use(express.cookieSession({ secret: nconf.get('SESSION_SECRET'), httpOnly: false, cookie: { maxAge: 60 * 60 * 1000 }}));
|
||||
//app.use(express.session());
|
||||
app.use(middleware.splash);
|
||||
app.use(middleware.locals);
|
||||
app.use(app.router);
|
||||
app.use(express['static'](path.join(__dirname, "/../public")));
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ html
|
|||
// CSS
|
||||
link(rel='stylesheet', href='/bower_components/bootstrap/docs/assets/css/bootstrap.css')
|
||||
link(rel='stylesheet', href='/bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css')
|
||||
link(rel='stylesheet', href='/bower_components/angular-ui/build/angular-ui.css')
|
||||
link(rel='stylesheet', href='/bower_components/angular-ui/build/angular-ui.min.css')
|
||||
!= css('index')
|
||||
|
||||
// HabitRPG Shared
|
||||
|
|
@ -22,18 +22,18 @@ html
|
|||
|
||||
// JS
|
||||
script(type='text/javascript', src='/bower_components/jquery/jquery.min.js')
|
||||
script(type='text/javascript', src='/bower_components/lodash/lodash.js')
|
||||
script(type='text/javascript', src='/bower_components/moment/moment.js')
|
||||
script(type='text/javascript', src='/bower_components/lodash/dist/lodash.min.js')
|
||||
script(type='text/javascript', src='/bower_components/bootstrap-growl/jquery.bootstrap-growl.min.js')
|
||||
script(type='text/javascript', src='/bower_components/angular/angular.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-route/angular-route.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-resource/angular-resource.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-ui/build/angular-ui.js')
|
||||
script(type='text/javascript', src='/bower_components/moment/min/moment.min.js')
|
||||
script(type='text/javascript', src='/bower_components/angular/angular.min.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-route/angular-route.min.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-resource/angular-resource.min.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-ui/build/angular-ui.min.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-ui-utils/modules/keypress/keypress.js')
|
||||
// we'll remove this once angular-bootstrap is fixed
|
||||
script(type='text/javascript', src='/bower_components/bootstrap/docs/assets/js/bootstrap.min.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-bootstrap/ui-bootstrap.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-bootstrap/ui-bootstrap-tpls.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-bootstrap/ui-bootstrap.min.js')
|
||||
script(type='text/javascript', src='/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js')
|
||||
|
||||
// Sortable
|
||||
script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.core.min.js')
|
||||
|
|
|
|||
Loading…
Reference in a new issue