31 lines
721 B
TypeScript
31 lines
721 B
TypeScript
import { Application, Router } from 'oak';
|
|
import { authenticateUser } from 'middleware/auth.ts';
|
|
|
|
type servicePrefix = `/${string}`;
|
|
|
|
interface IServiceOpts {
|
|
prefix: servicePrefix;
|
|
}
|
|
|
|
export class CGGService<T> extends Application<T & {user?: string}> {
|
|
public prefix: servicePrefix;
|
|
|
|
constructor(options: IServiceOpts) {
|
|
super();
|
|
|
|
this.prefix = options.prefix;
|
|
this.use(authenticateUser);
|
|
// this.baseRouter = new Router({prefix: this.prefix});
|
|
}
|
|
start() {
|
|
const port = Deno.args.at(0);
|
|
this.listen({ port: port ? Number(port) : undefined })
|
|
}
|
|
|
|
route(router: Router) {
|
|
router.prefix(this.prefix);
|
|
this.use(router.routes())
|
|
this.use(router.allowedMethods());
|
|
}
|
|
}
|