mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-04 04:59:40 +00:00
Use constants for is_prod and base_url
This commit is contained in:
parent
675808e54e
commit
93a2d3d660
1 changed files with 13 additions and 16 deletions
|
|
@ -14,8 +14,11 @@ var os = require('os');
|
|||
var moment = require('moment');
|
||||
var utils = require('./utils');
|
||||
|
||||
var IS_PROD = nconf.get('NODE_ENV') === 'production';
|
||||
var BASE_URL = nconf.get("BASE_URL");
|
||||
|
||||
module.exports.apiThrottle = function(app) {
|
||||
if (nconf.get('NODE_ENV') !== 'production') return;
|
||||
if (!IS_PROD) return;
|
||||
app.use(limiter({
|
||||
end:false,
|
||||
catagories:{
|
||||
|
|
@ -33,7 +36,7 @@ module.exports.apiThrottle = function(app) {
|
|||
}
|
||||
|
||||
module.exports.domainMiddleware = function(server,mongoose) {
|
||||
if (nconf.get('NODE_ENV')=='production') {
|
||||
if (IS_PROD) {
|
||||
var mins = 3, // how often to run this check
|
||||
useAvg = false, // use average over 3 minutes, or simply the last minute's report
|
||||
url = 'https://api.newrelic.com/v2/applications/'+nconf.get('NEW_RELIC_APPLICATION_ID')+'/metrics/data.json?names[]=Apdex&values[]=score';
|
||||
|
|
@ -88,13 +91,11 @@ module.exports.errorHandler = function(err, req, res, next) {
|
|||
}
|
||||
|
||||
function isHTTP(req) {
|
||||
var baseUrl = nconf.get("BASE_URL");
|
||||
|
||||
return (
|
||||
req.headers['x-forwarded-proto'] &&
|
||||
req.headers['x-forwarded-proto'] !== 'https' &&
|
||||
nconf.get('NODE_ENV') === 'production' &&
|
||||
baseUrl.indexOf('https') === 0
|
||||
IS_PROD &&
|
||||
BASE_URL.indexOf('https') === 0
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -106,30 +107,26 @@ function isProxied(req) {
|
|||
}
|
||||
|
||||
module.exports.forceSSL = function(req, res, next){
|
||||
var baseUrl = nconf.get("BASE_URL");
|
||||
|
||||
if(isHTTP(req) && !isProxied(req)) {
|
||||
return res.redirect(baseUrl + req.url);
|
||||
return res.redirect(BASE_URL + req.url);
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
// Redirect to habitica for non-api urls
|
||||
// NOTE: Currently using a static 'habitica.com' string, rather than baseUrl,
|
||||
// to make rollback easy. Eventually, baseUrl should be migrated.
|
||||
// NOTE: Currently using a static 'habitica.com' string, rather than BASE_URL,
|
||||
// to make rollback easy. Eventually, BASE_URL should be migrated.
|
||||
|
||||
function nonApiUrl(req) {
|
||||
return req.url.search(/\/api\//) === -1;
|
||||
}
|
||||
|
||||
module.exports.forceHabitica = function(req, res, next) {
|
||||
var baseUrl = nconf.get('BASE_URL');
|
||||
var isProd = nconf.get('NODE_ENV') === 'production';
|
||||
var isHabitRPG = req.headers.host === 'habitrpg.com';
|
||||
|
||||
if(isProd && isHabitRPG && !isProxied(req) && nonApiUrl(req)) {
|
||||
return res.redirect(baseUrl + req.url);
|
||||
if(IS_PROD && isHabitRPG && !isProxied(req) && nonApiUrl(req)) {
|
||||
return res.redirect('https://habitica.com' + req.url);
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
|
@ -192,7 +189,7 @@ var getManifestFiles = function(page){
|
|||
|
||||
var code = '';
|
||||
|
||||
if(nconf.get('NODE_ENV') === 'production'){
|
||||
if(IS_PROD){
|
||||
code += '<link rel="stylesheet" type="text/css" href="' + getBuildUrl(page + '.css') + '">';
|
||||
code += '<script type="text/javascript" src="' + getBuildUrl(page + '.js') + '"></script>';
|
||||
}else{
|
||||
|
|
|
|||
Loading…
Reference in a new issue