Spaces:
Running on Zero
Running on Zero
File size: 1,182 Bytes
6c0a39c 2ad3a4f 6c0a39c 2ad3a4f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // Production host for the m.ai API on a Hugging Face Space (Docker): plain Node http server around app.mjs.
// Listens on PORT (7860 on Spaces). Keys and settings come from the Space's secrets and variables.
import http from 'node:http';
import {init,handle,drain,providerCheck} from './app.mjs';
const settings=init(process.env);
const server=http.createServer((req,res)=>{
if(req.url==='/'&&['GET','HEAD'].includes(req.method)){ // the Space's own page: no data, just a sign of life
res.writeHead(200,{'Content-Type':'text/plain; charset=utf-8','Cache-Control':'no-store','X-Content-Type-Options':'nosniff'});
return res.end('m.ai API is running. The website is https://mai-alus.web.app\n');
}
handle(req,res);
});
server.headersTimeout=15e3; server.requestTimeout=60e3; server.keepAliveTimeout=5e3;
process.on('SIGTERM',()=>{drain();server.close(()=>process.exit(0));setTimeout(()=>process.exit(0),10e3).unref();});
server.listen(Number(process.env.PORT||7860),process.env.HOST||'0.0.0.0',()=>
{console.log(JSON.stringify({t:new Date().toISOString(),level:'info',event:'listening',port:server.address().port,...settings}));
providerCheck().catch(()=>{});});
|