Created
April 23, 2020 00:15
-
-
Save notpushkin/375fd33ebb05af7c4ace91c4d80385d4 to your computer and use it in GitHub Desktop.
Sapper patch to make <base> optional (based on https://github.com/sveltejs/sapper/pull/984) - https://github.com/sveltejs/sapper/issues/228
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/sapper/runtime/app.mjs b/node_modules/sapper/runtime/app.mjs | |
index 6dd39c7..602bfdf 100644 | |
--- a/node_modules/sapper/runtime/app.mjs | |
+++ b/node_modules/sapper/runtime/app.mjs | |
@@ -356,7 +356,7 @@ async function hydrate_target(target) | |
} | |
function load_css(chunk) { | |
- const href = `client/${chunk}`; | |
+ const href = initial_data.baseUrl + `/client/${chunk}`; | |
if (document.querySelector(`link[href="${href}"]`)) return; | |
return new Promise((fulfil, reject) => { | |
diff --git a/node_modules/sapper/runtime/server.mjs b/node_modules/sapper/runtime/server.mjs | |
index 405b635..7934b96 100644 | |
--- a/node_modules/sapper/runtime/server.mjs | |
+++ b/node_modules/sapper/runtime/server.mjs | |
@@ -2534,7 +2534,7 @@ function get_page_handler( | |
}); | |
styles = Array.from(css_chunks) | |
- .map(href => `<link rel="stylesheet" href="client/${href}">`) | |
+ .map(href => `<link rel="stylesheet" href="${req.baseUrl}/client/${href}">`) | |
.join(''); | |
} else { | |
styles = (css && css.code ? `<style>${css.code}</style>` : ''); | |
@@ -2544,7 +2544,7 @@ function get_page_handler( | |
const nonce_attr = (res.locals && res.locals.nonce) ? ` nonce="${res.locals.nonce}"` : ''; | |
const body = template() | |
- .replace('%sapper.base%', () => `<base href="${req.baseUrl}/">`) | |
+ .replace('%sapper.base%', () => req.baseTag ? `<base href="${req.baseUrl}/">` : '<!-- no base -->') | |
.replace('%sapper.scripts%', () => `<script${nonce_attr}>${script}</script>`) | |
.replace('%sapper.html%', () => html) | |
.replace('%sapper.head%', () => `<noscript id='sapper-head-start'></noscript>${head}<noscript id='sapper-head-end'></noscript>`) | |
@@ -2608,12 +2608,15 @@ function middleware(opts | |
= {}) { | |
- const { session, ignore } = opts; | |
+ const { session, ignore, baseTag = true } = opts; | |
let emitted_basepath = false; | |
return compose_handlers(ignore, [ | |
(req, res, next) => { | |
+ if (req.baseTag === undefined) { | |
+ req.baseTag = baseTag | |
+ } | |
if (req.baseUrl === undefined) { | |
let { originalUrl } = req; | |
if (req.url === '/' && originalUrl[originalUrl.length - 1] !== '/') { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment