18 lines
757 B
JavaScript
18 lines
757 B
JavaScript
|
|
import fs from 'node:fs'
|
||
|
|
import path from 'node:path'
|
||
|
|
|
||
|
|
// Serve generated page-update artifacts only, matching the previous dev server.
|
||
|
|
export default function mobileUpdate() {
|
||
|
|
return {name:'cmvr-mobile-update',configureServer(server){
|
||
|
|
server.middlewares.use((req,res,next)=>{
|
||
|
|
const name=(req.url||'').split('?')[0].slice(1)
|
||
|
|
if(name!=='mobile-update.json'&&!/^web-[a-f0-9]{24}\.zip$/.test(name))return next()
|
||
|
|
const file=path.resolve(server.config.root,'dist',name)
|
||
|
|
if(!fs.existsSync(file)){res.statusCode=404;res.end();return}
|
||
|
|
res.setHeader('Cache-Control','no-store')
|
||
|
|
res.setHeader('Content-Type',name.endsWith('.json')?'application/json':'application/zip')
|
||
|
|
fs.createReadStream(file).pipe(res)
|
||
|
|
})
|
||
|
|
}}
|
||
|
|
}
|