lab20230426
This commit is contained in:
commit
58dda43a15
16
Welcome file.html
Normal file
16
Welcome file.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Welcome file</title>
|
||||||
|
<link rel="stylesheet" href="https://stackedit.io/style.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="stackedit">
|
||||||
|
<div class="stackedit__html"><h1 id="артур-козёл-я-больше-не-буду-дружить-с-тобой">АРТУР КОЗЁЛ!!! Я БОЛЬШЕ НЕ БУДУ ДРУЖИТЬ С ТОБОЙ!!!</h1>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
28
file.js
Normal file
28
file.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
const http = require('http');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const server = http.createServer((req, res) => {
|
||||||
|
//console.log(req)
|
||||||
|
|
||||||
|
|
||||||
|
fs.readFile('./'+req.url, (err, data) => {
|
||||||
|
if(err){
|
||||||
|
res.writeHead(404, "Not Found");
|
||||||
|
res.write("No file found");
|
||||||
|
res.end();
|
||||||
|
} else {
|
||||||
|
res.writeHead(200, {
|
||||||
|
'Content-Length': data.length,
|
||||||
|
'Content-Type': 'text/html'
|
||||||
|
})
|
||||||
|
res.write(data);
|
||||||
|
res.end();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
server.on('clientError', (err, socket) => {
|
||||||
|
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
|
||||||
|
});
|
||||||
|
server.listen(8088, () => {
|
||||||
|
console.log("listen on http://localhost:8088/");
|
||||||
|
});
|
16
index.html
Normal file
16
index.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Welcome file</title>
|
||||||
|
<link rel="stylesheet" href="https://stackedit.io/style.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="stackedit">
|
||||||
|
<div class="stackedit__html"><h1 id="артур-козёл-я-больше-не-буду-дружить-с-тобой">АРТУР КОЗЁЛ!!! Я БОЛЬШЕ НЕ БУДУ ДРУЖИТЬ С ТОБОЙ!!!</h1>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
28
index.js
Normal file
28
index.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
const net = require('net');
|
||||||
|
const fs = require('fs');
|
||||||
|
const server = net.createServer((c) => {
|
||||||
|
// 'connection' listener.
|
||||||
|
console.log('client connected');
|
||||||
|
c.on('end', () => {
|
||||||
|
console.log('client disconnected');
|
||||||
|
});
|
||||||
|
//c.write('HTTP/1.1 200 OK\r\nContent-Length: 12\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nHello World!');
|
||||||
|
fs.readFile('./Welcome file.html', (err, data) => {
|
||||||
|
c.write('HTTP/1.1 200 OK\r\n');
|
||||||
|
c.write('Content-Length: '+data.length+'\r\n');
|
||||||
|
c.write('Content-Type: text/html; charset=utf-8\r\n');
|
||||||
|
c.write('\r\n');
|
||||||
|
c.write(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
//c.pipe(c);
|
||||||
|
c.on('data', (data) => {
|
||||||
|
console.log(data.toString());
|
||||||
|
})
|
||||||
|
});
|
||||||
|
server.on('error', (err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
server.listen(8124, () => {
|
||||||
|
console.log('server bound');
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user