clonegur/backend/routers/StaticRouter.ts

23 lines
717 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() {
2023-06-30 21:49:40 +00:00
return stream(`var $_url = "${this.apiUrl}";`);
2023-06-30 21:25:21 +00:00
}
2023-06-30 21:49:40 +00:00
@route('*') static = staticHandler('static');
@rest('GET', '*')
2023-06-30 21:25:21 +00:00
async index() {
return new RestResponse()
.body((await Deno.open('static/index.html')).readable)
.contentType('html');
}
public constructor(private apiUrl: string) {
super();
}
}