【问题标题】:Getting Error in hosting angular 6 on A2hosting windows server在 A2hosting Windows 服务器上托管 Angular 6 时出错
【发布时间】:2018-07-31 14:57:06
【问题描述】:

我正在尝试在 a2hosting windows server 安装节点中部署 angular 6 应用程序并创建快速服务器代码

const express = require('express');
const http = require('http');
const path = require('path');

const app = express();

const port = process.env.PORT || 3001;

app.use(express.static(__dirname + '/dist/website-name'));

app.get('/*', (req, res) => res.sendFile(path.join(__dirname)));

const server = http.createServer(app);

server.listen(port, () => console.log("Running...."));

我使用 Angular CLI 构建了用于生产的应用程序:

ng build -prod

However, I receive these errors when I connect

Image for network

【问题讨论】:

  • 尝试使用 app.get('/', ... 而不使用 *
  • 试过了,但也没用
  • 你为什么要在路由('/')上发送文件?删除此行。如果您想提供图片等静态资源,请将它们放在/assets 文件夹中,这就是它的目的。

标签: javascript angular typescript angular-cli angular6


【解决方案1】:

这很可能是由于您没有构建到您计划托管文件的域。

ng build --prod --bh /myWebsiteSubDomain/

检查您的网络选项卡并查看这些 http 请求的去向。

【讨论】:

  • 什么是 myWebsiteSubDomain 是我的 url 或我的域的根目录?
  • 如果您将网站托管在根目录上,那么这不是解决方案。你能提供一些你的网络请求的截图吗? (开发者工具的网络标签,重新加载页面,悬停在红色请求上)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多