Boilerplate generator and deno tasks for monorepo
This commit is contained in:
30
lib/Application.ts
Normal file
30
lib/Application.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user