node.js - axios 获取请求返回我尝试服务的所有静态 html 文件的 vue index.html 文件
问题描述
所以,我有一个在我的 MAC 上运行良好的 vue 应用程序npm run serve
。
运行npm run build
我的代码并将其部署到我的 CENTOS 环境(使用 NGINX),所有返回的 .get 请求都在网络选项卡中返回 200,但内容应该是我要拉入我的应用程序的静态 html 文件。
以下是一些代码示例:
this.axios.get(flatHtmlLocation).then(response => {
let corsHTML = response.data;
let htmlDoc = (new DOMParser()).parseFromString(corsHTML, "text/html");
this.rawDog = htmlDoc;
this.htmlData = htmlDoc.documentElement.getElementsByTagName('body')[0].innerHTML;
})
^ 当我在我的 Mac 上玩耍时,这很好用。
我正在从特定目录中的 /public/ 目录中提取我的静态 .html 文件。
这是我的文件结构的样子:
应用程序名称
-- public
index.html
/directory-where-static-html-lives/filename.html
-- src
-- components/component/file_pulling_the_static_asset.vue
这是我正在使用的产品中应用程序的 .conf (NGINX) 文件的副本:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location /api/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_buffering off;
proxy_pass http://some-fancy-pants-url:4000;
}
location /public/ {
root /opt/location-of-my-app;
}
location / {
root /opt/location-of-my-app/dist;
index index.html index.htm;
include /etc/nginx/mime.types;
try_files $uri $uri/ /index.html;
}
}
解决方案
推荐阅读
- keycloak - Kong OIDC:发现 url 超时
- angular - 如何修复 IIS 错误(不允许使用 PUT 方法)
- azure-devops - 将 Azure Devops 组织正确链接到 Azure AD 帐户
- git - MATLAB - 在脚本中临时签出 git 提交
- sql - 通过执行触发器自动插入其他表中的最大值
- class - Dart:从自身内部引用 Singleton 类
- java - 在 Android Studio 中使用 Google Places API 时找不到汽车修理店/车库/汽车店
- c++ - 有没有一种可能的方法将 for 循环结果返回到像三元运算符这样的函数中?
- c# - 具有多行的 WPF 水平 ListView
- android - Android 应用内结算 - 如何处理退款