35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
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";
|
|
import staticHandler from "../server/staticHandler.ts";
|
|
|
|
export class RootRouter extends AppRouter {
|
|
@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;
|
|
|
|
@rest('*', '*')
|
|
default() {
|
|
return new RestResponse().body(stream('Page not found :/')).status(404);
|
|
}
|
|
|
|
constructor(salt: string, db: AppDatabase) {
|
|
super();
|
|
|
|
this.static = staticHandler('static');
|
|
this.users = new UserRouter(salt, db);
|
|
this.images = new ImageRouter(db);
|
|
}
|
|
}
|