mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
fix hard links for new client (#8986)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import locals from '../../middlewares/locals';
|
import locals from '../../middlewares/locals';
|
||||||
|
import { serveClient } from '../../libs/client';
|
||||||
// import _ from 'lodash';
|
// import _ from 'lodash';
|
||||||
// import md from 'habitica-markdown';
|
// import md from 'habitica-markdown';
|
||||||
// import nconf from 'nconf';
|
// import nconf from 'nconf';
|
||||||
@@ -92,7 +93,7 @@ api.getNewClient = {
|
|||||||
url: '/',
|
url: '/',
|
||||||
noLanguage: true,
|
noLanguage: true,
|
||||||
async handler (req, res) {
|
async handler (req, res) {
|
||||||
return res.sendFile('./dist-client/index.html', {root: `${__dirname}/../../../../`});
|
return serveClient(res);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
// }
|
// }
|
||||||
|
|||||||
5
website/server/libs/client.js
Normal file
5
website/server/libs/client.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const ROOT = `${__dirname}/../../../`;
|
||||||
|
|
||||||
|
export function serveClient (expressRes) {
|
||||||
|
return expressRes.sendFile('./dist-client/index.html', {root: ROOT});
|
||||||
|
}
|
||||||
@@ -1,7 +1,34 @@
|
|||||||
import {
|
import {
|
||||||
NotFound,
|
NotFound,
|
||||||
} from '../libs/errors';
|
} from '../libs/errors';
|
||||||
|
import { serveClient } from '../libs/client';
|
||||||
|
|
||||||
|
// Serve the client side unless the route starts with one of these strings
|
||||||
|
// in which case, respond with a 404 error.
|
||||||
|
const TOP_LEVEL_ROUTES = [
|
||||||
|
'/api',
|
||||||
|
'/amazon',
|
||||||
|
'/iap',
|
||||||
|
'/paypal',
|
||||||
|
'/stripe',
|
||||||
|
'/export',
|
||||||
|
'/email',
|
||||||
|
'/qr-code',
|
||||||
|
// logout, old-client and /static/user/auth/local/reset-password-set-new-one don't need the not found
|
||||||
|
// handler because they don't have any child route
|
||||||
|
];
|
||||||
|
|
||||||
module.exports = function NotFoundMiddleware (req, res, next) {
|
module.exports = function NotFoundMiddleware (req, res, next) {
|
||||||
next(new NotFound());
|
const reqUrl = req.originalUrl;
|
||||||
|
|
||||||
|
const isExistingRoute = TOP_LEVEL_ROUTES.find(routeRoot => {
|
||||||
|
if (reqUrl.lastIndexOf(routeRoot, 0) === 0) return true; // starts with
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isExistingRoute || req.method !== 'GET') {
|
||||||
|
return next(new NotFound());
|
||||||
|
} else {
|
||||||
|
serveClient(res);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const IS_PROD = nconf.get('IS_PROD');
|
|||||||
// const IS_NEW_CLIENT_ENABLED = nconf.get('NEW_CLIENT_ENABLED') === 'true';
|
// const IS_NEW_CLIENT_ENABLED = nconf.get('NEW_CLIENT_ENABLED') === 'true';
|
||||||
const MAX_AGE = IS_PROD ? 31536000000 : 0;
|
const MAX_AGE = IS_PROD ? 31536000000 : 0;
|
||||||
const ASSETS_DIR = path.join(__dirname, '/../../assets');
|
const ASSETS_DIR = path.join(__dirname, '/../../assets');
|
||||||
const PUBLIC_DIR = path.join(__dirname, '/../../client');
|
const PUBLIC_DIR = path.join(__dirname, '/../../client-old'); // TODO static files are still there
|
||||||
const BUILD_DIR = path.join(__dirname, '/../../build');
|
const BUILD_DIR = path.join(__dirname, '/../../build');
|
||||||
|
|
||||||
module.exports = function staticMiddleware (expressApp) {
|
module.exports = function staticMiddleware (expressApp) {
|
||||||
|
|||||||
Reference in New Issue
Block a user