Spaces:
Running on Zero
Running on Zero
Download api/main.mjs from mohith2309/mai-api: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/mohith2309/mai-api/resolve/main/api/main.mjs
- Command line
-
hf download hf://spaces/mohith2309/mai-api/api/main.mjs
-
curl -L -o main.mjs https://huggingface.co/spaces/mohith2309/mai-api/resolve/main/api/main.mjs
1.18 kB
| // 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(()=>{});}); | |