server: servedPath is a URL path not file path

Thus we shall not use path.join(). Or NodeJS will helpfully convert
the paths to Windows format if we are on Windows and as a result,
breaks everything.

Fixes: fee968525, 8f4fb88ac
This commit is contained in:
Jesse Chan
2020-09-21 15:19:13 +08:00
parent 6849e9c55b
commit 327a491af2
3 changed files with 23 additions and 6 deletions
+5 -5
View File
@@ -33,8 +33,8 @@ app.use(cookieParser());
passportConfig(passport);
app.use(path.join(paths.servedPath, 'api'), apiRoutes);
app.use(path.join(paths.servedPath, 'auth'), authRoutes);
app.use(`${paths.servedPath}api`, apiRoutes);
app.use(`${paths.servedPath}auth`, authRoutes);
// After routes, look for static assets.
app.use(paths.servedPath, express.static(paths.appDist));
@@ -42,15 +42,15 @@ app.use(paths.servedPath, express.static(paths.appDist));
// Client app routes, serve index.html and client js will figure it out
const html = fs.readFileSync(path.join(paths.appDist, 'index.html'), {encoding: 'utf8'});
app.get(path.join(paths.servedPath, 'login'), (_req, res) => {
app.get(`${paths.servedPath}login`, (_req, res) => {
res.send(html);
});
app.get(path.join(paths.servedPath, 'register'), (_req, res) => {
app.get(`${paths.servedPath}register`, (_req, res) => {
res.send(html);
});
app.get(path.join(paths.servedPath, 'overview'), (_req, res) => {
app.get(`${paths.servedPath}overview`, (_req, res) => {
res.send(html);
});
+15
View File
@@ -0,0 +1,15 @@
declare const PATHS: {
appBuild: string;
appDist: string;
appPublic: string;
appHtml: string;
appIndex: string;
appPackageJson: string;
appSrc: string;
clientSrc: string;
testsSetup: string;
appNodeModules: string;
servedPath: string;
};
export = PATHS;
+3 -1
View File
@@ -30,7 +30,7 @@ const getAppDist = () => {
return appDist;
};
module.exports = {
const PATHS = {
appBuild: resolveApp('dist/assets'),
appDist: getAppDist(),
appPublic: resolveApp('client/src/public/'),
@@ -43,3 +43,5 @@ module.exports = {
appNodeModules: resolveApp('node_modules'),
servedPath: ensureSlash(userConfig.baseURI || '/', true),
};
module.exports = PATHS;