clonegur/backend/routers/StaticRouter.ts

23 lines
716 B
TypeScript
Raw Normal View History

2023-06-30 21:25:21 +00:00
import { rest, route } from "../server/decorators.ts";
import RestResponse from "../server/RestResponse.ts";
import staticHandler from "../server/staticHandler.ts";
import { stream } from "../utils/utils.ts";
import AppRouter from "./AppRouter.ts";
export class StaticRouter extends AppRouter {
@rest('GET', '/http-url.js')
getHttpUrl() {
return stream(`var $_url = ${this.apiUrl};`);
}
@rest('GET', '/')
async index() {
return new RestResponse()
.body((await Deno.open('static/index.html')).readable)
.contentType('html');
}
@route('/*') static = staticHandler('static');
public constructor(private apiUrl: string) {
super();
}
}