35 lines
740 B
TypeScript
35 lines
740 B
TypeScript
import { createServer } from 'node:http';
|
|
import fs from 'node:fs';
|
|
|
|
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,
|
|
transport: 'unix', // 指定传输方式为 Unix 套接字
|
|
port: 10004,
|
|
},
|
|
() => {
|
|
console.log('Server is running on. \ncurl --unix-socket /tmp/http-listen.sock http://localhost/api/router?path=demo');
|
|
throw new Error('test');
|
|
},
|
|
);
|
|
|
|
// Deno.serve(
|
|
// {
|
|
// path: socketPath,
|
|
// transport: 'unix',
|
|
// },
|
|
// async (req) => {
|
|
// console.log(req.url);
|
|
// return new Response('Hello World2');
|
|
// },
|
|
// );
|