sdin
Version:
JavaScript package builder.
2 lines • 1.08 kB
JavaScript
import r from"koa";import e from"koa-mount";import a from"koa-proxy";import i from"koa-logger";import o from"koa-static";import s from"express-to-koa";import m from"webpack-dev-middleware";import p from"webpack-hot-middleware";import{resolvePosixSlash as h}from"../../utils/path";function t(t,e){let o=new r;return t.devLog&&o.use(i()),t.devProxies.forEach(t=>{o.use(a(t))}),o.use(s(m(e,{stats:"errors-warnings",publicPath:t.path}))),o.use(s(p(e))),o.use(u(t)),o.use(n(t,e)),o}function u(t){return e(t.withPath(t.astPath),o(t.astSrc))}function n(r,a){let i=h(r.path,!0,!1),s={};for(var t of r.pages)s[r.withPath(t.path)]=t;return async o=>{if(("GET"===o.method||"HEAD"===o.method)&&!o.body&&404===o.status&&null!=(t=o.headers.accept)&&t.includes("text/html")){var t=h(o.path,!0,!1);let e=void 0;if(e=t===i?r.index||r.error:s[t]||r.error){let t=r.withTar("htm/".concat([e.path],".html"));o.set("content-type","text/html"),o.body=await new Promise((o,r)=>{a.outputFileSystem&&a.outputFileSystem.readFile(t,(t,e)=>t?r(t):o(e))})}}}}export{t as createKoa};
//# sourceMappingURL=koa.js.map