clonegur/backend/routers/RootRouter.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-06-29 14:31:25 +00:00
import UserRouter from "../routers/UserRouter.ts";
import ImageRouter from "./ImageRouter.ts";
import AppRouter from "./AppRouter.ts";
import RestResponse from "../server/RestResponse.ts";
import { rest, route } from "../server/decorators.ts";
import { stream } from "../utils/utils.ts";
import AppDatabase from "../AppDatabase.ts";
2023-06-30 00:37:07 +00:00
import staticHandler from "../server/staticHandler.ts";
2023-06-29 14:31:25 +00:00
export class RootRouter extends AppRouter {
2023-06-30 00:37:07 +00:00
@route('api/users/*') users;
@route('api/images/*') images;
@rest('GET', '/')
async index() {
return new RestResponse()
.body((await Deno.open('static/index.html')).readable)
.contentType('html');
}
@route('/*') static;
2023-06-29 14:31:25 +00:00
2023-06-30 10:19:21 +00:00
@rest('OPTIONS', '*')
options() {
return new RestResponse();
}
2023-06-29 14:31:25 +00:00
@rest('*', '*')
default() {
return new RestResponse().body(stream('Page not found :/')).status(404);
}
constructor(salt: string, db: AppDatabase) {
super();
2023-06-30 00:37:07 +00:00
this.static = staticHandler('static');
2023-06-29 14:31:25 +00:00
this.users = new UserRouter(salt, db);
this.images = new ImageRouter(db);
}
}