From b5b9cb7e2f17f6b55053bd43b70ceeb93c12df21 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 12 Jul 2019 19:11:11 +0000 Subject: [PATCH] feat: support static uri's with paths (#2399) --- src/core/build/createWebpackConfig.ts | 5 +++++ src/core/server/app/helpers/entrypoints.ts | 6 +----- src/core/server/app/router/index.ts | 4 +++- src/core/server/config.ts | 9 ++++----- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/core/build/createWebpackConfig.ts b/src/core/build/createWebpackConfig.ts index 8cf2231be..fbd64a9de 100644 --- a/src/core/build/createWebpackConfig.ts +++ b/src/core/build/createWebpackConfig.ts @@ -499,6 +499,11 @@ export default function createWebpackConfig( exclude: [/\.(js|ts|tsx)$/, /\.html$/, /\.json$/], loader: require.resolve("file-loader"), options: { + // Because the resources loaded via CSS can sometimes be loaded + // directly from a CSS file, this will ensure that they are + // relative to those referencing files. + publicPath: (loaderPublicPath: string) => + "../../" + loaderPublicPath, name: isProduction ? "assets/media/[name].[hash:8].[ext]" : "assets/media/[name].[ext]", diff --git a/src/core/server/app/helpers/entrypoints.ts b/src/core/server/app/helpers/entrypoints.ts index 556ac41b0..dd0341050 100644 --- a/src/core/server/app/helpers/entrypoints.ts +++ b/src/core/server/app/helpers/entrypoints.ts @@ -70,11 +70,7 @@ export default class Entrypoints { // Check to see if the asset is a match. if (asset.src === src) { - entrypoint[extension].push({ - integrity: asset.integrity, - // Prefix all the sources with a `/`. - src: "/" + asset.src, - }); + entrypoint[extension].push(asset); break; } } diff --git a/src/core/server/app/router/index.ts b/src/core/server/app/router/index.ts index a202479e9..73c2b4cb1 100644 --- a/src/core/server/app/router/index.ts +++ b/src/core/server/app/router/index.ts @@ -31,7 +31,9 @@ export function createRouter(app: AppOptions, options: RouterOptions) { if (!options.disableClientRoutes) { mountClientRoutes(router, { - staticURI: app.config.get("static_uri"), + // When mounting client routes, we need to provide a staticURI even when + // not provided to the default current domain relative "/". + staticURI: app.config.get("static_uri") || "/", tenantCache: app.tenantCache, }); } else { diff --git a/src/core/server/config.ts b/src/core/server/config.ts index 0e8ea3b4d..adeec5189 100644 --- a/src/core/server/config.ts +++ b/src/core/server/config.ts @@ -4,6 +4,7 @@ import { parseConnectionString } from "mongodb-core"; import os from "os"; import { LOCALES } from "coral-common/helpers/i18n/locales"; +import { ensureEndSlash } from "coral-common/utils"; import { InternalError } from "./errors"; @@ -32,7 +33,7 @@ convict.addFormat({ }, }); -// Add a custom format for the optional-url. +// Add a custom format for the optional-url that includes a trailing slash. convict.addFormat({ name: "optional-url", validate: (url: string) => { @@ -40,10 +41,8 @@ convict.addFormat({ Joi.assert(url, Joi.string().uri()); } }, - // Ensure that there is no ending slash. - coerce: (url: string) => { - return url.replace(/\/$/, ""); - }, + // Ensure that there is an ending slash. + coerce: (url: string) => (url ? ensureEndSlash(url) : url), }); const config = convict({