jetc 0.6.4 → 0.6.5
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/bin/server.js +4 -5
- package/package.json +1 -1
package/bin/server.js
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
'use strict';function l(a){return n.existsSync(a)&&n.statSync(a).isDirectory()}function r(a){return n.existsSync(a)&&n.statSync(a).isFile()}function t(...a){a=a.join("/").split("/");let c=a.length;for(let b=1;b<c;b++)0<b&&b<c-1&&!a[b]?(a.splice(b,1),--c,--b):0<b&&"."===a[b]?(a.splice(b,1),--c,--b):1===b&&".."===a[b]&&"."===a[b-1]?(a.splice(b-1,1),--c,--b):0<b&&".."===a[b]&&"."!==a[b-1]&&".."!==a[b-1]&&(a.splice(b-1,2),c-=2,b-=2);return a.join("/")}
|
|
3
3
|
function u(a,c){try{return require.resolve(a,c).replace(/\\/g,"/")}catch(b){}return null}function v(a,c){return"\u001b["+a+"m"+c+"\u001b[39m"}function w(){return v(90,"["+(new Date).toLocaleString("en-US")+"]")}function z(a){return(a=B(a))?{"Content-Type":a}:null}
|
|
4
4
|
function B(a){a=a.split("/");var c=a[a.length-1].split(".");a={css:"text/css",csv:"text/csv",eot:"application/vnd.ms-fontobject",gif:"image/gif",htm:"text/html",html:"text/html",ico:"image/vnd.microsoft.icon",jpeg:"image/jpeg",jpg:"image/jpeg",js:"application/javascript",json:"application/json",otf:"font/otf",pdf:"application/pdf",png:"image/png",svg:"image/svg+xml",tif:"image/tiff",tiff:"image/tiff",ttf:"font/ttf",txt:"text/plain",woff:"font/woff",woff2:"font/woff2",xml:"text/xml"};return 1<c.length&&
|
|
5
|
-
(c=c[c.length-1],a[c])?a[c]:null}const n=require("fs"),C=require("http");function D(){var a=process.argv;let c=!1,b="",f=3E3;const
|
|
5
|
+
(c=c[c.length-1],a[c])?a[c]:null}const n=require("fs"),C=require("http");function D(){var a=process.argv;let c=!1,b="",f=3E3;const e=a.length;for(let k=2;k<e;k++){const d=a[k];d.startsWith("--port=")?f=parseInt(d.slice(7),10):d.startsWith("--all=")?c=d.slice(6):"--all"===d?c="/index.html":k===e-1&&(b=d)}return{a:c,folder:b,port:f}}function E(a,c){a=a.headers.accept;let b=!0;if(a){const f=B(c);b=!1;a.split(",").forEach(e=>{e=e.split(";")[0].trim();if(e===f||"*/*"===e)b=!0})}return b}
|
|
6
6
|
function F(a){let c="";a=a.split("/").map(f=>{f=c+f;c=f+"/";return[f,f+"/node_modules"]}).reverse();const b=a.length;for(let f=0;f<b;f++)if(l(a[f][1]))return a[f][0];return null}
|
|
7
|
-
function G(){const {a,folder:c,port:b}=D(),f=C.createServer((
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
require.main===module&&G();
|
|
7
|
+
function G(){const {a,folder:c,port:b}=D(),f=C.createServer((e,k)=>{{var d=e.url.split("?")[0];var g=process.cwd().replace(/\\/g,"/");var m=c?t(g,c):g,p=t(m,a);const q=t(m,d),A=t(q,"index.html");var h="";g="";if(r(q))h=q,g=d;else if(r(A))h=A,g=t(d,"index.html");else if(0===d.indexOf("/node_modules/")){if(d=d.split("/node_modules/"),p=F(m),m=d.pop(),p&&m&&(h=t(p,d.join("/node_modules/")),h=u(m,{paths:[h]})))d=h.split("/node_modules/"),d[0]="",g=d.join("/node_modules/")}else"/"!==d&&(h=u(t(".",d),{paths:[m]}))&&
|
|
8
|
+
(g=h.slice(m.length)),h||(h=u(d.slice(1),{paths:[m]}))&&(g=t("/node_modules/",h.split("/node_modules/").pop())),h||!a||1<d.split("/").pop().split(".").length||!r(p)||(h=p,g=t(a));g={filename:h,location:g}}const {filename:x,location:y}=g;g="";if(x&&E(e,x)){try{g=n.readFileSync(x,"binary")}catch(q){g=q;e=e.url;k.writeHead(500,z(".txt"));k.write("500 Internal Server Error\n");k.end();console.log(w(),'"GET '+e+'" '+v(31,500)+" "+g);return}e=e.url;h=Object.assign({},{Location:y},z(y),{"Cache-Control":"max-age=0, no-cache, must-revalidate, proxy-revalidate",
|
|
9
|
+
Expires:"Thu, 01 Jan 1970 00:00:00 GMT","Last-Modified":(new Date).toUTCString()});k.writeHead(200,h);k.write(g,"binary");k.end();console.log(w(),'"GET '+e+'" 200 '+g.length+" "+y)}else e=e.url,k.writeHead(404,z(".txt")),k.write("404 Not Found\n"),k.end(),console.log(w(),'"GET '+e+'" '+v(31,404))});f.on("error",e=>console.error(e));f.listen(b,"localhost");console.log("Development server is running at http://localhost:"+b+"/\nPress Ctrl + C to shutdown.\n")}require.main===module&&G();
|