mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Added redirects to habitica for non-API urls
This commit is contained in:
@@ -115,6 +115,21 @@ module.exports.forceSSL = function(req, res, next){
|
|||||||
next();
|
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.
|
||||||
|
|
||||||
|
function nonApiUrl(req) {
|
||||||
|
return req.url.search(/\/api\//) === -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.forceHabitica = function(req, res, next) {
|
||||||
|
if(nconf.get('NODE_ENV') === 'production' && req.hostname !== 'habitica.com' && nonApiUrl(req)) {
|
||||||
|
return res.redirect('https://habitica.com' + req.url);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.cors = function(req, res, next) {
|
module.exports.cors = function(req, res, next) {
|
||||||
res.header("Access-Control-Allow-Origin", req.headers.origin || "*");
|
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-Methods", "OPTIONS,GET,POST,PUT,HEAD,DELETE");
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ if (cores!==0 && cluster.isMaster && (isDev || isProd)) {
|
|||||||
app.set("view engine", "jade");
|
app.set("view engine", "jade");
|
||||||
app.use(express.favicon(publicDir + '/favicon.ico'));
|
app.use(express.favicon(publicDir + '/favicon.ico'));
|
||||||
app.use(middleware.cors);
|
app.use(middleware.cors);
|
||||||
|
app.use(middleware.forceHabitica);
|
||||||
app.use(middleware.forceSSL);
|
app.use(middleware.forceSSL);
|
||||||
app.use(express.urlencoded());
|
app.use(express.urlencoded());
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|||||||
Reference in New Issue
Block a user