Commit bd747dc7 authored by nanahira's avatar nanahira

fix http

parent c315ed5b
This diff is collapsed.
......@@ -77,11 +77,12 @@ export namespace DoRegister {
),
);
export const route = registry.define('route', (data, ctx, obj, key) =>
ctx.router[data.method](data.path, (koaCtx, next) =>
export const route = registry.define('route', (data, ctx, obj, key) => {
const path = data.path.startsWith('/') ? data.path : `/${data.path}`;
return ctx.router[data.method](path, (koaCtx, next) =>
obj[key](koaCtx, next),
),
);
});
export const ws = registry.define('ws', (data, ctx, obj, key) =>
ctx.router.ws(data, (socket, request) => obj[key](socket, request)),
......
import { App } from 'koishi';
import { Get } from '../src/decorators';
import { KoaContext } from '../src/def';
import request from 'supertest';
import { Registrar } from '../src/register';
class MyClass {
@Get('ping')
async ping(ctx: KoaContext) {
ctx.status = 233;
ctx.body = 'pong';
}
}
const registrar = new Registrar(new MyClass());
describe('Http Routes', () => {
let app: App;
beforeEach(() => {
app = new App();
});
it('should be able to get a route', async () => {
registrar.register(app, 'ping');
await app.start();
return request(app._httpServer).get('/ping').expect(233).expect('pong');
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment