UNPKG

houdini-adapter-node

Version:

The adapter for deploying your Houdini application as a standalone node server

2 lines (1 loc) 1.04 kB
import{createServerAdapter as d}from"houdini/adapter";import*as r from"node:fs";import{createServer as f}from"node:http";import a,{dirname as g}from"node:path";import{fileURLToPath as u}from"node:url";var h=u(import.meta.url),i=g(h),v=d({production:!0,assetPrefix:"/assets"}),x=f((s,e)=>{if(s.url&&s.url.startsWith("/assets"))return j(s,e);v(s,e)}),c=process.env.PORT??3e3;x.listen(c,()=>{console.log(`Server is listening on port ${c} \u{1F680}`)});function j(s,e){let o=a.join(i,s.url==="/"?"index.html":s.url??"/"),m=a.extname(o),t="text/html";switch(m){case".js":t="application/javascript";break;case".css":t="text/css";break;case".json":t="application/json";break;case".png":t="image/png";break;case".jpg":t="image/jpg";break;case".ico":t="image/x-icon";break;default:t="text/html"}r.readFile(o,(n,p)=>{n?n.code==="ENOENT"?r.readFile(a.join(i,"404.html"),(S,l)=>{e.writeHead(404,{"Content-Type":"text/html"}),e.end(l,"utf8")}):(e.writeHead(500),e.end(`Server Error: ${n.code}`)):(e.writeHead(200,{"Content-Type":t}),e.end(p,"utf8"))})}