[英]File with CSS and JS files not serving on server and prints ��U�v�8��+
When I run my hapijs app locally it is working but when I deploy it in the server it doesn't work.当我在本地运行我的 hapijs 应用程序时,它可以正常工作,但是当我将它部署在服务器中时,它不起作用。 The page can serve html files but if the HTML file has css or bootsrap then it prints weird symbols like ��U�v�8��+
该页面可以提供 html 个文件,但如果 HTML 文件有 css 或 bootsrap,那么它会打印奇怪的符号,如�U�v�8�+
The link that shows the weird response: https://us-central1-fir-app-85853.cloudfunctions.net/v1/teacher/list显示奇怪响应的链接: https://us-central1-fir-app-85853.cloudfunctions.net/v1/teacher/list
Here is my index.js file.这是我的 index.js 文件。
How can I fix this issue?我该如何解决这个问题?
'use strict';
const functions = require('firebase-functions');
const api = require('./server');
exports.v1 = functions.https.onRequest(async (event, resp) => {
let server = await api.startServer();
const options = {
method: event.httpMethod,
headers: event.headers,
url: event.path,
payload: event.body
};
return server
.inject(options)
.then(response => {
delete response.headers['content-encoding']
delete response.headers['transfer-encoding']
response.headers['x-powered-by'] = 'hapijs'
resp.set(response.headers);
return resp.status(response.statusCode).send(response.result);
})
.catch(error => resp.status(500).send(error.message || "unknown error"));
});
Here is my full source code on github https://github.com/kartikgreen/hapijs-firebase这是我在 github https://github.com/kartikgreen/hapijs-firebase上的完整源代码
This is very likely a character encoding issue.这很可能是字符编码问题。
There are a few causes, one is a different character encoding being outputted than UTF-8.有几个原因,一个是输出的字符编码与 UTF-8 不同。
so say your document outputs in ISO-8859-1 (known as Latin-1), if you do not set the character set the browser will default to UTF-8. Think of it like outputting chinese and then asking a language parser to treat it as japanese, it will never understand!所以说你的文档输出为 ISO-8859-1(称为 Latin-1),如果你没有设置字符集,浏览器将默认为 UTF-8。把它想象成输出中文然后要求语言解析器将其视为日语,它永远听不懂!
Not sure how to do it in hapjs but in PHP you would just add a header as follows:-不确定如何在 hapjs 中执行此操作,但在 PHP 中,您只需添加一个 header,如下所示:-
header("Content-Type: text/html; charset=ISO-8859-1");
The other possible cause is a Byte Order Mark (BOM) .另一个可能的原因是 字节顺序标记 (BOM) 。
If your script is accidentally outputting some blank data before it should this can add these invisible characters.如果你的脚本在它应该之前不小心输出了一些空白数据,这可以添加这些不可见的字符。
There are loads of answers on BOMs on Stack Overflow so I won't repeat those. Stack Overflow 上有很多关于 BOM 的答案,所以我不会重复这些。
I would normally say run the page through the W3C Internationalisation Checker but your page seems to kill it (which could be down to firebase).我通常会说通过W3C 国际化检查器运行该页面,但您的页面似乎将其杀死(这可能归结为 firebase)。 Perhaps you could capture the raw output to a file and run it through that way?
也许您可以将原始 output 捕获到一个文件中并通过这种方式运行它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.