2025-04-18 03:22:29 +08:00

60 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// import { App } from "@kevisual/router";
import { App } from '@kevisual/router/router';
import path from 'node:path';
import fs from 'node:fs';
import http, { Server } from 'node:http';
// https://esm.sh/@kevisual/router@0.0.12/dist/router.d.ts
// https://esm.sh/@kevisual/router@0.0.13/dist/router.d.ts
// https://esm.sh/@kevisual/router@0.0.13/dist/router.d.ts
console.log('meta', import.meta.url);
// deno run --allow-all index.ts
// deno run --config ./deno.json --allow-all index.ts
console.log('hello world');
const app = new App({
io: true,
});
app
.route({
path: 'demo',
})
.define(async (ctx) => {
ctx.body = 'hello world';
})
.addTo(app);
const socketPath = path.resolve('/tmp/http-deno.sock');
// const socketPath = path.resolve(Deno.cwd(), './http.sock');
if (fs.existsSync(socketPath)) {
fs.unlinkSync(socketPath);
}
// app.listen(10004, () => {
// console.log('Server is running on http://localhost:10004');
// });
// process.umask(0); // 设置默认权限掩码
// app.listen(socketPath, () => {
// // console.log('Server is running on. \ncurl --unix-socket ./http-deno.sock http://localhost/api/router?path=demo');
// console.log('Server is running on. \ncurl --unix-socket /tmp/http-deno.sock http://localhost/api/router?path=demo');
// console.log(`Actual path: ${fs.realpathSync(socketPath)}`);
// });
const sv = app.server.server as Server;
sv.listen(socketPath, () => {
console.log('Server is running on. \ncurl --unix-socket /tmp/http-deno.sock http://localhost/api/router?path=demo');
console.log(`Actual path: ${fs.realpathSync(socketPath)}`);
});
app.server.server.on('error', (err) => {
console.error('error', err);
});
app.io.addListener('goo', async ({ data, ws, end }) => {
console.log('goo', data);
end({
code: 200,
message: 'hello world goo',
});
});