diff options
Diffstat (limited to 'packages/astro/src/vite-plugin-astro-server/index.ts')
-rw-r--r-- | packages/astro/src/vite-plugin-astro-server/index.ts | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index ba5b54813..f6da58546 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -339,18 +339,18 @@ async function handleRequest( * Vite HMR sends requests for new CSS and those get returned as JS, but we want it to be CSS * since they are inside of a link tag for Astro. */ -const forceTextCSSForStylesMiddleware: vite.Connect.NextHandleFunction = function(req, res, next) { - if(req.url) { +const forceTextCSSForStylesMiddleware: vite.Connect.NextHandleFunction = function (req, res, next) { + if (req.url) { // We are just using this to parse the URL to get the search params object // so the second arg here doesn't matter const url = new URL(req.url, 'https://astro.build'); // lang.css is a search param that exists on Astro, Svelte, and Vue components. // We only want to override for astro files. - if(url.searchParams.has('astro') && url.searchParams.has('lang.css')) { + if (url.searchParams.has('astro') && url.searchParams.has('lang.css')) { // Override setHeader so we can set the correct content-type for this request. const setHeader = res.setHeader; - res.setHeader = function(key, value) { - if(key.toLowerCase() === 'content-type') { + res.setHeader = function (key, value) { + if (key.toLowerCase() === 'content-type') { return setHeader.call(this, key, 'text/css'); } return setHeader.apply(this, [key, value]); @@ -381,7 +381,10 @@ export default function createPlugin({ config, logging }: AstroPluginOptions): v removeViteHttpMiddleware(viteServer.middlewares); // Push this middleware to the front of the stack so that it can intercept responses. - viteServer.middlewares.stack.unshift({ route: '', handle: forceTextCSSForStylesMiddleware }); + viteServer.middlewares.stack.unshift({ + route: '', + handle: forceTextCSSForStylesMiddleware, + }); viteServer.middlewares.use(async (req, res) => { if (!req.url || !req.method) { throw new Error('Incomplete request'); |