UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

43 lines (37 loc) 1.05 kB
import history from 'connect-history-api-fallback' import fs from 'fs' import path from 'path' import {type Plugin} from 'vite' /** * This is a Vite plugin for supporting locations containing `.` in their pathname. * * @see https://github.com/vitejs/vite/issues/2245 */ export function sanityDotWorkaroundPlugin(): Plugin { return { name: 'sanity/server/dot-workaround', configureServer(server) { const {root} = server.config return () => { const handler = history({ disableDotRule: true, rewrites: [ { from: /\/index.html$/, to: ({parsedUrl}) => { const pathname = parsedUrl.pathname if (pathname && fs.existsSync(path.join(root, pathname))) { return pathname } return `/index.html` }, }, ], }) server.middlewares.use((req, res, next) => { handler(req as any, res as any, next) }) } }, } }