Skip to content

Commit

Permalink
Allow to customize mount point
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Oct 6, 2022
1 parent 065775e commit c4c4bfa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/koa/src/KoaAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
} from '@bull-board/api/dist/typings/app';

import Koa from 'koa';
import Router from 'koa-router';
import mount from 'koa-mount';
import path from 'path';
import Router from 'koa-router';
import serve from 'koa-static';
import views from 'koa-views';
import path from 'path';

export class KoaAdapter implements IServerAdapter {
private basePath = '';
Expand Down Expand Up @@ -60,7 +60,7 @@ export class KoaAdapter implements IServerAdapter {
return this;
}

public registerPlugin() {
public registerPlugin(options: Partial<{ mount: string }> = { mount: this.basePath }) {
if (!this.statics) {
throw new Error(`Please call 'setStaticPath' before using 'registerPlugin'`);
} else if (!this.entryRoute) {
Expand All @@ -75,6 +75,10 @@ export class KoaAdapter implements IServerAdapter {
throw new Error(`Please call 'setErrorHandler' before using 'registerPlugin'`);
}

if (!options.mount) {
options.mount = this.basePath;
}

const app = new Koa();
const router = new Router({
strict: true,
Expand Down Expand Up @@ -130,6 +134,6 @@ export class KoaAdapter implements IServerAdapter {

app.use(router.routes()).use(router.allowedMethods());

return mount(this.basePath || '', app);
return mount(options.mount || '/', app);
}
}

0 comments on commit c4c4bfa

Please sign in to comment.