使用 Oak
,如何在没有扩展的情况下提供 HTML?例如
host:port/home.html
-> host:port/home
这是我当前用于呈现 public/views
文件夹的代码:
router.get('/:page', async (ctx: Context, next: () => Promise<unknown>) => {
await send(ctx, ctx.request.url.pathname, {
root: join(Deno.cwd(), 'public', 'views'),
extensions: ['htm', 'html']
});
await next();
});
extensions
选项不起作用,或者我可能只是以错误的方式使用它。
我的修复目前正在删除 .html
扩展名(例如 home.html
-> home
)。很确定有比这更好的方法
答案 0 :(得分:0)
您可以使用它来发送文件:
router.get('/path', async (ctx:any) => {
const text = await Deno.readTextFile('./file.html');
ctx.response.headers.set("Content-Type", "text/html")
ctx.response.body = text;
});