mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
http.js
This commit is contained in:
38
rootfs_overlay/lkmc/nodejs/http.js
Executable file
38
rootfs_overlay/lkmc/nodejs/http.js
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// https://cirosantilli.com/linux-kernel-module-cheat#node-js
|
||||
|
||||
const http = require('http');
|
||||
const util = require('util');
|
||||
const url = require('url');
|
||||
|
||||
http.createServer(
|
||||
(req, res) => {
|
||||
const myUrl = new url.URL(req.url, 'http://example.com');
|
||||
const searchString = [];
|
||||
for (const [key, value] of myUrl.searchParams) {
|
||||
searchString.push(`<div>${key}: ${value}</div>\n`)
|
||||
}
|
||||
const reqString = [];
|
||||
for (let prop of Object.keys(req).sort()) {
|
||||
reqString.push(`<div>${prop}: ${util.inspect(req[prop])}</div>\n`);
|
||||
}
|
||||
ret = `<!doctype html>
|
||||
<html lang=en>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>hello html</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>req.url: ${req.url}</div>
|
||||
<div>url.pathname: ${myUrl.pathname}</div>
|
||||
<div>url.search:</div>
|
||||
${searchString.join('')}
|
||||
<div>req:</div>
|
||||
${reqString.join('')}
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
res.write(ret);
|
||||
res.end();
|
||||
}).listen(8080);
|
||||
Reference in New Issue
Block a user