Skip to content

Commit faded27

Browse files
save file
1 parent 5c1e593 commit faded27

File tree

1 file changed

+72
-18
lines changed

1 file changed

+72
-18
lines changed

blog/25-07-24/http-server/ex/login-server.js

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,22 @@
1919

2020
}//switch
2121

22-
var type = mime(path);
22+
var txt;
23+
var code = 200;
24+
switch(oath){
2325

24-
res.writeHead(200,{'content-type':type});
25-
require('fs').createReadStream(path).pipe(res);
26-
27-
}//request
28-
29-
30-
function mime(path){
31-
32-
var ext = path.split('.').at(-1),type;
33-
switch(ext){
34-
35-
case 'html' : return 'text/html';
36-
case 'js' : return 'text/javascript';
37-
case 'css' : return 'text/css';
26+
case 'home.html' : txt=html.home; break;
27+
case 'login.html' : txt=html.login; break;
3828

29+
default : txt=html.notfound;
30+
code=404;
31+
3932
}//switch
40-
return 'application/octet-stream';
4133

42-
}//mime
34+
res.writeHead(code,{'content-type':'text/html'});
35+
res.end(txt);
36+
37+
}//request
4338

4439

4540
function post(req){
@@ -119,4 +114,63 @@
119114

120115
}//admin
121116

122-
117+
//:
118+
119+
var html = {};
120+
121+
html.home = `
122+
<style>
123+
h3{display:flex;align-items:center;gap:10px}
124+
a{margin:10px}
125+
</style>
126+
<h3>
127+
<img src='data:image/webp;base64,UklGRsYCAABXRUJQVlA4WAoAAAAQAAAAHQAAGQAAQUxQSEQBAAABgLNt2/F2Q88RvlttW5v5ZaxtrtGeOd28BVttTsGmudYU1HYb1NGnNiImAP4r428KUwEY8VhLC5aMaEiVZaHq+SPb15ftSN3rRwYVVkUBf71+yuYi/FJnk2Dz1tYL+617vy6yR9VEgHg7O2suqkcYXnCVmN9v/SBnu7+/mffzQc2ydavV6iJ/alQrhzAftl9UVGHVFgVcYwDgo/4POl4xAv7jxvoTNZcYz092eH3ppEGKF9U84qJ+b1S34LFR7y+198ujXjwA7JWay/XbQhSwTsdRPBFUK3Wum1sKSiCJlCbXk43cUbYPI7igQyQSaV1Uv8TgG9ExsLJ++eGi+jWEACAiisFgsINTq6SqS1LPUj8UXCAR+QEhSu0YPbQT3KpU+sN1kR+QZkSU9akOL+0fHx/2S70kFWhkR6QWVFWVFaQi+I9WUDggXAEAAHAJAJ0BKh4AGgA+kUCaSiWjoiGoCACwEglsAJ0yhHV3s3CGbEmSPsB4un+A/gHYA3hreNv249JYwATPYXkhwRyxHA4AtmKE3v8Fe1hEjGxF8yTViAD+93f7uzp/cY6ee3cA/ABmw2BiLBBVJKJz/g+cTgthx8Ebkftx2bQEJ3MflzgosWtuKltj/hI3RMoAwFxeBmu+eSJtbRgZ61ptIxyi2MdEDCHjPj3jX/opDt6LYy9ANPrxM63NhtMHlfxAVPpzvXcXYj84f1o/Lm7EYg5vf/264/ub16UBvELBYFRTSG1Q6wi37a7tFWHTD8aa9H5txf/ovVaLWiyh7unAHE2QicwcSI90vHadzi8AAqKMc8FXPp/6Vr/JoQOFEyOav3ySNoeHDpeofn5plRg2Kp2pgj7OAxFkvtfut7l5r0N7JZcZOXQoMv5ML/VcchnpevFx9GBdPtEtrDwAAA=='>
128+
home
129+
</h3>
130+
<div>
131+
<a href='login.html'>login</a>
132+
<a href='admin.html'>admin</a>
133+
</div>
134+
`;
135+
html.login = `
136+
<style>
137+
form{border:1px solid lightgray;padding:10px;display:inline-flex;flex-direction:column;gap:10px}
138+
label{width:60px;text-align:right;display:inline-block;margin:10px}
139+
h4,span{text-align:center;margin:0}
140+
input{font-size:16;padding:5px 10px}
141+
</style>
142+
<form action='login' method=post>
143+
<h4>login</h4>
144+
<div>
145+
<label for=name>name</label>
146+
<input name=name>
147+
</div>
148+
<div>
149+
<label for=password>password</label>
150+
<input name=password>
151+
</div>
152+
<span>
153+
<input type=submit>
154+
</span>
155+
</form>
156+
`;
157+
html.admin = `
158+
<style>
159+
h3{color:green;font-style:italic}
160+
a{margin:10px}
161+
</style>
162+
<h3>admin</h3>
163+
<div>
164+
<a href='home.html'>home</a>
165+
<a href='logout'>logout</a>
166+
</div>
167+
`;
168+
html.notfound = `
169+
<style>
170+
a{margin:10px}
171+
</style>
172+
<h3>not found</h3>
173+
<a href='home.html'>home</a>
174+
<a href='login.html'>login</a>
175+
<a href='admin.html'>admin</a>
176+
`;

0 commit comments

Comments
 (0)