简体   繁体   English

如何将Heroku托管指向子目录中的angular应用和index.html?

[英]How to point heroku hosting to angular app and index.html in subdirectory?

I'm new to deploying with heroku. 我是第一次使用heroku进行部署。 Inside of my heroku repo, I have an nodejs + angular app where my app.js and all angular files are inside of a subdirectory called app/ 在我的heroku存储库中,我有一个nodejs + angular应用程序,其中我的app.js和所有angular文件都在名为app/的子目录中

I use grunt, and I can run my site locally without problem, and I go to localhost:8000/app . 我使用grunt,可以毫无问题地在本地运行我的网站,然后转到localhost:8000/app When I push to heroku, it goes through my package.json and runs the appropriate scripts to build the project. 当我推送到heroku时,它会遍历我的package.json并运行适当的脚本来构建项目。 I have also already done 我也已经做过

heroku ps:scale web=1

However, when I try 但是,当我尝试

heroku open

The page says: 该页面显示:

Application Error An error occurred in the application and your page could not be served. 应用程序错误应用程序中发生错误,无法提供您的页面。 Please try again in a few moments. 请稍后重试。

I believe this is because heroku isn't pointed to app/index.html , so there is no page to render. 我相信这是因为heroku没有指向app/index.html ,所以没有要呈现的页面。 Is there any fix for this? 有没有解决办法?

What does your web server configuration file (app.js/webserver.js or whatever you've named it) look like? 您的Web服务器配置文件(app.js / webserver.js或您命名的文件)是什么样的?

Here's a sample one using Express: 这是使用Express的示例:

var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var session = require('express-session');

var app = express();

var port = process.env.PORT || 8000;

var path = require('path');
var rootPath = path.normalize(__dirname + '/');
app.use(express.static(rootPath + '/app'));



app.listen(port, function (err) {
  console.log('running server on port ' + port);
});

Heroku should have no trouble finding your index.html within your app folder if the above is configured properly. 如果以上配置正确,Heroku在您的应用程序文件夹中找到index.html应该没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM