@moneko/core 4.2.0-beta.1 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dev/server.mjs +1 -1
- package/package.json +1 -1
package/lib/dev/server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createServer as e}from"node:http";import{createServer as t}from"node:https";import{platform as o}from"node:os";import{extname as r,join as n,sep as i}from"node:path";import{env as s}from"node:process";import{ink as a,println as m}from"@moneko/utils";import{CA_ORGANIZATION as l,isCertificateInstalled as p}from"../commom/ca.mjs";import c from"../commom/mime.mjs";import d from"../commom/open.mjs";import{CONFIG as C}from"../config.mjs";import f from"../dev/get-cert.mjs";import{setupProxy as h}from"../dev/proxy.mjs";import u,{cacheBody as A}from"./mock.mjs";let E={"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"Authorization, Content-Type, Accept, X-Requested-With, Origin, DNT, User-Agent, Cache-Control, X-CSRF-Token, X-API-Key, X-Client-Version, X-Device-ID, Content-Language, Accept-Language, X-Custom-Header, X-Mx-ReqToken, Keep-Alive, If-Modified-Since","Access-Control-Allow-Methods":"GET, DELETE, HEAD, OPTIONS, POST, PUT, PATCH, PURGE, LINK, UNLINK, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, REPORT, SEARCH, CONNECT, TRACE","Access-Control-Allow-Origin":"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0"};async function y(y){let T=n(y.root_dir,"index.html"),g=u();function w(e,t,o){let n=e.headers["accept-encoding"],i=n?.includes("br"),s=`${o}.${i?"br":"gz"}`,a=y.fileSystem.existsSync(s);a&&t.setHeader("Content-Encoding",i?"br":"gzip");let m=y.fileSystem.createReadStream(a?s:o,{autoClose:!0});m.on("open",()=>{t.writeHead(200,Object.assign({},E,y.headers,{"Access-Control-Allow-Origin":e.headers.origin??"*","Content-Type":c[r(o)]||"application/octet-stream"}))}),m.on("error",e=>{switch(m.readable=!0,e.code){case"ENOENT":t.writeHead(301,{Location:"/index.html"}),t.end();break;case"EACCES":t.writeHead(403,{"Content-Type":"text/plain"}),t.end(`Forbidden: ${e.message}`);break;default:t.writeHead(500,{"Content-Type":"text/plain"}),t.end(`Internal Server Error: ${e.message}`)}}),m.pipe(t)}async function O(e,t){if(A(e),!(y.onRequest&&y.onRequest(e,t))){if(!(C.proxy&&await h(e,t,C.proxy)||t.writableEnded||g&&g(e,t))&&!t.writableEnded){if("GET"===e.method){let o="/"===e.url?T:decodeURIComponent(n(y.root_dir,e.url.replace(y.basename??"/","/")));if(y.fileSystem.existsSync(o))return w(e,t,o)}if(e.headers.accept?.includes("text/html"))return w(e,t,T);t.writeHead(404,{"Content-Type":"text/plain"}),t.end("File Not Found")}}}let x=y.https?t(await f(y.host,!0===y.https?{install:!0}:y.https),O):e(O);if(x.listen(y.port),y.https&&!await p(l)&&"darwin"===o()){let e=s.npm_execpath?.split(i).pop()?.split(".").shift()||"npm",t=s.npm_lifecycle_event??"start",o=`> sudo ${e} ${t}`;m(a("⚠️ 未检测到本地 SSL 证书,请通过以下命令重启项目以安装证书: ","yellow")),m(a(o,"yellow")),m("")}return y.open&&d(`${y.https?"https:":"http:"}//${y.host}:${y.port}${"/"===y.basename?"":y.basename}`),x}export default y;
|
|
1
|
+
import{createServer as e}from"node:http";import{createServer as t}from"node:https";import{platform as o}from"node:os";import{extname as r,join as n,sep as i}from"node:path";import{env as s}from"node:process";import{ink as a,println as m}from"@moneko/utils";import{CA_ORGANIZATION as l,isCertificateInstalled as p}from"../commom/ca.mjs";import c from"../commom/mime.mjs";import d from"../commom/open.mjs";import{CONFIG as C}from"../config.mjs";import f from"../dev/get-cert.mjs";import{setupProxy as h}from"../dev/proxy.mjs";import u,{cacheBody as A}from"./mock.mjs";let E={"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Headers":"Authorization, Content-Type, Accept, X-Requested-With, Origin, DNT, User-Agent, Cache-Control, X-CSRF-Token, X-API-Key, X-Client-Version, X-Device-ID, Content-Language, Accept-Language, X-Custom-Header, X-Mx-ReqToken, Keep-Alive, If-Modified-Since","Access-Control-Allow-Methods":"GET, DELETE, HEAD, OPTIONS, POST, PUT, PATCH, PURGE, LINK, UNLINK, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, REPORT, SEARCH, CONNECT, TRACE","Access-Control-Allow-Origin":"*","Cache-Control":"no-store, no-cache, must-revalidate, proxy-revalidate",Pragma:"no-cache",Expires:"0"};async function y(y){let T=n(y.root_dir,"index.html"),g=u();function w(e,t,o){let n=e.headers["accept-encoding"],i=n?.includes("br"),s=`${o}.${i?"br":"gz"}`,a=y.fileSystem.existsSync(s);a&&t.setHeader("Content-Encoding",i?"br":"gzip");let m=y.fileSystem.createReadStream(a?s:o,{autoClose:!0});m.on("open",()=>{t.writeHead(200,Object.assign({},E,y.headers,{"Access-Control-Allow-Origin":e.headers.origin??"*","Content-Type":c[r(o)]||"application/octet-stream"}))}),m.on("error",e=>{switch(m.readable=!0,e.code){case"ENOENT":t.writeHead(301,{Location:"/index.html"}),t.end();break;case"EACCES":t.writeHead(403,{"Content-Type":"text/plain"}),t.end(`Forbidden: ${e.message}`);break;default:t.writeHead(500,{"Content-Type":"text/plain"}),t.end(`Internal Server Error: ${e.message}`)}}),m.pipe(t)}async function O(e,t){if(A(e),!(y.onRequest&&y.onRequest(e,t))){if(!(C.proxy&&await h(e,t,C.proxy)||t.writableEnded||g&&g(e,t))&&!t.writableEnded){if("GET"===e.method){let o=("/"===e.url?T:decodeURIComponent(n(y.root_dir,e.url.replace(y.basename??"/","/")))).split("?")[0];if(y.fileSystem.existsSync(o))return w(e,t,o)}if(e.headers.accept?.includes("text/html"))return w(e,t,T.split("?")[0]);t.writeHead(404,{"Content-Type":"text/plain"}),t.end("File Not Found")}}}let x=y.https?t(await f(y.host,!0===y.https?{install:!0}:y.https),O):e(O);if(x.listen(y.port),y.https&&!await p(l)&&"darwin"===o()){let e=s.npm_execpath?.split(i).pop()?.split(".").shift()||"npm",t=s.npm_lifecycle_event??"start",o=`> sudo ${e} ${t}`;m(a("⚠️ 未检测到本地 SSL 证书,请通过以下命令重启项目以安装证书: ","yellow")),m(a(o,"yellow")),m("")}return y.open&&d(`${y.https?"https:":"http:"}//${y.host}:${y.port}${"/"===y.basename?"":y.basename}`),x}export default y;
|