Files
aigc-home/e2e/hel818-web.cjs
T
2026-10-23 18:46:06 +08:00

9 lines
1015 B
JavaScript

// Test-only static build server. Every API request goes to our isolated API.
const http=require('node:http'),fs=require('node:fs'),path=require('node:path');
const build=path.resolve('calliope-web/build');
http.createServer((req,res)=>{
if(req.url.startsWith('/api/')||req.url.startsWith('/assets/')){const q=http.request('http://127.0.0.1:18247'+req.url,{method:req.method,headers:req.headers},r=>{res.writeHead(r.statusCode,r.headers);r.pipe(res)});q.on('error',()=>{res.statusCode=502;res.end()});res.on('close',()=>q.destroy());req.pipe(q);return}
let file=path.join(build,new URL(req.url,'http://localhost').pathname);if(!fs.existsSync(file)||fs.statSync(file).isDirectory())file=path.join(build,'index.html');
res.setHeader('Content-Type',({'.js':'text/javascript','.css':'text/css','.html':'text/html','.png':'image/png','.jpg':'image/jpeg','.woff2':'font/woff2','.svg':'image/svg+xml'})[path.extname(file)]||'application/octet-stream');fs.createReadStream(file).pipe(res);
}).listen(15173,'127.0.0.1');