简体   繁体   English

包含 CSS 的文件和未在服务器上提供的 JS 文件并打印 ��U��v��8��+

[英]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上的完整源代码

I just removed the 'accept-encoding': 'gzip, deflate, br' line in the request headers' object to not request gzip compression.我刚刚删除了请求标头 object 中的 'accept-encoding': 'gzip, deflate, br' 行,以不请求 gzip 压缩。

This answer is already in the link这个答案已经在链接

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.

相关问题 使用 go 递归地提供 static 文件 - Serving static files recursively with go Amazon Elastic Beanstalk 不提供 django static 个文件 - Amazon Elastic Beanstalk not serving django static files nginx 入口 controller 忽略 css 和 js 文件 - 谷歌 kuber.netes 引擎 - nginx ingress controller ignoring css and js files - google kuberenetes engine 我们如何使用 node.js 将 m3u8 文件和相应的 ts 文件上传到 amazon s3 存储桶 - How can we upload m3u8 file and corresponding ts file to amazon s3 bucket using node.js 有人可以引导我通过 S3 源从 Cloudfront 提供 gzip 文件吗? - Can someone walk me through serving gzipped files from Cloudfront via S3 origin? 直接下载存储在S3 bucket中的文件到React客户端,而不是通过Node.js服务器 - Download file stored in S3 bucket directly to React client, instead of passing through Node.js server 反应 JS 上的 Firebase v9 - Firebase v9 on react JS Node.js 从服务器上传图片文件到firebase失败 - Node.js failed to upload image file to firebase from the server 修改.m3u8 文件以使用 Cloudfront 对每个 url 进行签名 - Modify .m3u8 file to sign each url with Cloudfront Java AWS SDK v2:列出存储桶密钥,但仅列出文件 - Java AWS SDK v2: List bucket keys, but only the files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM