@mango-js/scripts
Version:
Scripts required for building and testing Mango applications
2 lines (1 loc) • 910 B
JavaScript
import p from"http";class h{constructor(a,n){this.port=a,this.classesLookup={},this.propsLookup={},this.classesCounter=1,this.propsCounter=1,this.handleReq=async(r,t)=>{const o=new URL(r.url,`http://${r.headers.host}`);if(o.pathname.startsWith("/classes/")){const i=o.pathname.slice(9).split(","),e={};for(const s of i)this.classesLookup[s]||(this.classesLookup[s]=this.classesCounter++),e[s]="a"+this.classesLookup[s];t.writeHead(200),t.end(JSON.stringify(e),"utf-8");return}else if(o.pathname.startsWith("/props/")){const i=o.pathname.slice(7).split(","),e={};for(const s of i)this.propsLookup[s]||(this.propsLookup[s]=this.propsCounter++),e[s]="a"+this.propsLookup[s];t.writeHead(200),t.end(JSON.stringify(e),"utf-8");return}t.writeHead(404),t.end("Not found","utf-8")},this.server=p.createServer(this.handleReq),this.server.listen(this.port,async()=>{await n(),this.server.close()})}}export{h as default};