我正在设置Angular-Deno堆栈概念证明。对于Angular应用程序生成,使用@angular/cli
版本9.1.9。生成应用程序后,我使用创建一个生产版本,npm run build -- --prod
输出在dist
应用程序的文件夹中。
deno服务器代码如下:
import { Application } from "https://deno.land/x/[email protected]/mod.ts";
const app = new Application();
app.static("/", "./client/dist/client");
app.file("/", "./client/dist/client/index.html");
app.start({ port: 8080 });
路径正确,内置的Angular应用位于中./client/dist/client
。
当我使用deno run --allow-net --allow-read .\server.ts
命令启动服务器并在浏览器中导航到` http:// localhost:8080 / url时,将下载Angular应用程序。一切正常。
但是,浏览器控制台上有一个警告:
Resource interpreted as Stylesheet but transferred with MIME type text/plain
我检查了index.html
Angular应用程序的生成,并且CSS参考如下:
<link rel="stylesheet" href="styles.09e2c710755c8867a460.css"></head>
如果我将以上更改<link>
为
<link type="text/css" href="styles.09e2c710755c8867a460.css"></head>
则说明一切正常,警告从浏览器控制台中消失。
有没有一种方法可以生成index.html
Angular应用,使其包含<link>
上面第二种方法的条目?还是deno请求管道中是否存在可以处理<link>
Angular应用程序最初生成的条目并正确设置CSS MIME的配置?
我想避免使用自定义<link>
的生成后脚本来更改生成的html的条目。
该link
标签是正确的,但该abc
框架没有设置正确Content-Type
的头css
文件,其实static
中间件不设置Content-Type
在所有的任何文件类型。
要解决此问题,您可以Content-Type
使用中间件来设置自己,也可以使用已内置该功能的框架。您可以使用Oak
。
import { Application, send } from "https://deno.land/x/oak/mod.ts";
const app = new Application();
app.use(async (context) => {
await send(context, context.request.url.pathname, {
root: `${Deno.cwd()}/client/dist/client`,
index: "index.html",
});
});
await app.listen({ port: 8080 });
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句