mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
expose new client at /new-app, can be enabled in prod setting a flag
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -33,6 +33,7 @@ coverage
|
|||||||
coverage.html
|
coverage.html
|
||||||
common/dist/scripts/*
|
common/dist/scripts/*
|
||||||
dist
|
dist
|
||||||
|
dist-client
|
||||||
test/client/unit/coverage
|
test/client/unit/coverage
|
||||||
test/client/e2e/reports
|
test/client/e2e/reports
|
||||||
test/client-old/spec/mocks/translations.js
|
test/client-old/spec/mocks/translations.js
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ var staticAssetsDirectory = './website/static/.'; // The folder where static fil
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
build: {
|
build: {
|
||||||
env: require('./prod.env'),
|
env: require('./prod.env'),
|
||||||
index: path.resolve(__dirname, '../../dist/index.html'),
|
index: path.resolve(__dirname, '../../dist-client/index.html'),
|
||||||
assetsRoot: path.resolve(__dirname, '../../dist'),
|
assetsRoot: path.resolve(__dirname, '../../dist-client'),
|
||||||
assetsSubDirectory: 'static',
|
assetsSubDirectory: 'static',
|
||||||
assetsPublicPath: '/',
|
assetsPublicPath: '/new-app',
|
||||||
staticAssetsDirectory: staticAssetsDirectory,
|
staticAssetsDirectory: staticAssetsDirectory,
|
||||||
productionSourceMap: true,
|
productionSourceMap: true,
|
||||||
// Gzip off by default as many popular static hosts such as
|
// Gzip off by default as many popular static hosts such as
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
`/website/client` contains the source files for the new client side that is being developed as part of the Habitica.com redesign.
|
`/website/client` contains the source files for the new client side that is being developed as part of the Habitica.com redesign. Static assets for the new client can be found in `website/static`.
|
||||||
|
|
||||||
The old client side files can be found in `/website/client-old`, they are still used on Habitica.com while the redesign is in progress.
|
The old client side files can be found in `/website/client-old`, they are still used on Habitica.com while the redesign is in progress.
|
||||||
@@ -7,7 +7,7 @@ Vue.use(VueRouter);
|
|||||||
|
|
||||||
export default new VueRouter({
|
export default new VueRouter({
|
||||||
mode: 'history',
|
mode: 'history',
|
||||||
base: __dirname,
|
base: process.env.NODE_ENV === 'production' ? '/new-app' : __dirname, // eslint-disable-line no-process-env
|
||||||
routes: [
|
routes: [
|
||||||
{ path: '/', component: Home },
|
{ path: '/', component: Home },
|
||||||
{ path: '/page', component: Page },
|
{ path: '/page', component: Page },
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import locals from '../../middlewares/locals';
|
import locals from '../../middlewares/locals';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import md from 'habitica-markdown';
|
import md from 'habitica-markdown';
|
||||||
|
import nconf from 'nconf';
|
||||||
|
|
||||||
let api = {};
|
let api = {};
|
||||||
|
|
||||||
|
const IS_PROD = nconf.get('IS_PROD');
|
||||||
const TOTAL_USER_COUNT = '1,500,000';
|
const TOTAL_USER_COUNT = '1,500,000';
|
||||||
const LOADING_SCREEN_TIPS = 32;
|
const LOADING_SCREEN_TIPS = 32;
|
||||||
|
const IS_NEW_CLIENT_ENABLED = nconf.get('NEW_CLIENT_ENABLED') === 'true';
|
||||||
|
|
||||||
api.getFrontPage = {
|
api.getFrontPage = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -82,5 +85,19 @@ api.redirectExtensionsPage = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// All requests to /new_app (expect /new_app/static) should serve the new client in development
|
||||||
|
if (IS_PROD && IS_NEW_CLIENT_ENABLED) {
|
||||||
|
api.getNewClient = {
|
||||||
|
method: 'GET',
|
||||||
|
url: /^\/new-app($|\/(?!(static\/.?|static$)))/,
|
||||||
|
async handler (req, res) {
|
||||||
|
if (!(req.session && req.session.userId)) {
|
||||||
|
return res.redirect('/static/front');
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.sendFile('./dist-client/index.html', {root: `${__dirname}/../../../../`});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -3,19 +3,22 @@ import nconf from 'nconf';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
const IS_PROD = nconf.get('IS_PROD');
|
const IS_PROD = nconf.get('IS_PROD');
|
||||||
|
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-old');
|
const PUBLIC_DIR = path.join(__dirname, '/../../client-old');
|
||||||
const BUILD_DIR = path.join(__dirname, '/../../build');
|
const BUILD_DIR = path.join(__dirname, '/../../build');
|
||||||
|
|
||||||
module.exports = function staticMiddleware (expressApp) {
|
module.exports = function staticMiddleware (expressApp) {
|
||||||
|
// Expose static files for new client
|
||||||
|
if (IS_PROD && IS_NEW_CLIENT_ENABLED) {
|
||||||
|
expressApp.use('/new-app/static', express.static(`${PUBLIC_DIR}/../../dist-client/static`));
|
||||||
|
}
|
||||||
|
|
||||||
// TODO move all static files to a single location (one for public and one for build)
|
// TODO move all static files to a single location (one for public and one for build)
|
||||||
expressApp.use(express.static(BUILD_DIR, { maxAge: MAX_AGE }));
|
expressApp.use(express.static(BUILD_DIR, { maxAge: MAX_AGE }));
|
||||||
expressApp.use('/assets/audio', express.static(`${ASSETS_DIR}/audio`, { maxAge: MAX_AGE }));
|
expressApp.use('/assets/audio', express.static(`${ASSETS_DIR}/audio`, { maxAge: MAX_AGE }));
|
||||||
expressApp.use('/assets/sprites', express.static(`${ASSETS_DIR}/sprites/dist`, { maxAge: MAX_AGE }));
|
expressApp.use('/assets/sprites', express.static(`${ASSETS_DIR}/sprites/dist`, { maxAge: MAX_AGE }));
|
||||||
expressApp.use('/assets/img', express.static(`${PUBLIC_DIR}/../../website/assets/img`, { maxAge: MAX_AGE }));
|
expressApp.use('/assets/img', express.static(`${PUBLIC_DIR}/../../website/assets/img`, { maxAge: MAX_AGE }));
|
||||||
expressApp.use(express.static(PUBLIC_DIR));
|
expressApp.use(express.static(PUBLIC_DIR));
|
||||||
|
|
||||||
// Expose new client when not in production
|
|
||||||
if (!IS_PROD) expressApp.use('/new-app', express.static(`${PUBLIC_DIR}/../client`));
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
This folder contains the source files for static assets used in the new client side that is being developed.
|
|
||||||
|
|
||||||
These files are served without passing through any preprocessor.
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Hello World!
|
|
||||||
Reference in New Issue
Block a user