mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-25 11:11:35 +01:00
more node
This commit is contained in:
35
rootfs_overlay/lkmc/nodejs/tmp/express.js
Executable file
35
rootfs_overlay/lkmc/nodejs/tmp/express.js
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const assert = require('assert')
|
||||
const http = require('http')
|
||||
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
const port = 3000
|
||||
|
||||
app.get('/error', async (req, res) => {
|
||||
throw 'my error'
|
||||
})
|
||||
|
||||
const server = app.listen(port, () => {
|
||||
// Test it.
|
||||
function test(path, method, status, body) {
|
||||
const options = {
|
||||
hostname: 'localhost',
|
||||
port: server.address().port,
|
||||
path: path,
|
||||
method: method,
|
||||
}
|
||||
http.request(options, res => {
|
||||
console.error(res.statusCode);
|
||||
assert(res.statusCode === status);
|
||||
res.on('data', d => {
|
||||
console.error(d.toString());
|
||||
if (body !== undefined) {
|
||||
assert(d.toString() === body);
|
||||
}
|
||||
})
|
||||
}).end()
|
||||
}
|
||||
test('/error', 'GET', 500, 'my error')
|
||||
})
|
||||
Reference in New Issue
Block a user