42 lines
954 B
TypeScript
42 lines
954 B
TypeScript
import { createServer } from 'node:http';
|
|
import * as fs from 'node:fs';
|
|
|
|
// import * as http from "jsr:@std/http";
|
|
|
|
const server = createServer((req, res) => {
|
|
res?.end('Hello World');
|
|
});
|
|
|
|
const socketPath = '/tmp/http-listen.sock';
|
|
if (fs.existsSync(socketPath)) {
|
|
fs.unlinkSync(socketPath);
|
|
}
|
|
|
|
server.listen({ path: socketPath }, () => {
|
|
console.log('Server is running on. \ncurl --unix-socket /tmp/http-listen.sock http://localhost/api/router?path=demo');
|
|
// throw new Error('test');
|
|
});
|
|
console.log(server);
|
|
console.log(Object.keys(server));
|
|
server.on('error', (err) => {
|
|
console.log(err);
|
|
});
|
|
console.log(server.address());
|
|
const req = '';
|
|
const res = {
|
|
end: (v: string) => {
|
|
console.log('end', v);
|
|
},
|
|
};
|
|
server.emit('request', req, res);
|
|
// Deno.serve(
|
|
// {
|
|
// path: socketPath,
|
|
// transport: 'unix',
|
|
// },
|
|
// async (req) => {
|
|
// console.log(req.url);
|
|
// return new Response('Hello World2');
|
|
// },
|
|
// );
|