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
26 lines (22 loc) • 576 B
text/typescript
import {type Plugin} from 'vite'
export function sanityBasePathRedirectPlugin(basePath: string | undefined): Plugin {
return {
name: 'sanity/server/sanity-base-path-redirect',
apply: 'serve',
configurePreviewServer(vitePreviewServer) {
return () => {
if (!basePath) {
return
}
vitePreviewServer.middlewares.use((req, res, next) => {
if (req.url !== '/') {
next()
return
}
res.writeHead(302, {Location: basePath})
res.end()
})
}
},
}
}