简体   繁体   English

如何准备一个angular.js应用程序部署到Heroku?

[英]How to prepare an angular.js app to deploy to Heroku?

I have built an Angular.js quiz app by following a video. 我通过观看视频构建了Angular.js测验应用程序。 I don't understand the workings of the app yet, but it works fine with Mozilla Developer Edition, not with other browsers because I run it locally. 我还不了解该应用程序的工作原理,但是它可以在Mozilla Developer Edition上正常运行,而不能与其他浏览器一起使用,因为我是在本地运行的。 My app's root directory contains the main HTML file, a JSON file, a folder for the CSS file, a folder for the images, and a folder for Angular.js files. 我的应用程序的根目录包含主HTML文件,一个JSON文件,一个用于CSS文件的文件夹,一个用于图像的文件夹以及一个Angular.js文件的文件夹。 When I try to deploy the app to Heroku, it gives me an error message saying 'No default language could be detected'. 当我尝试将应用程序部署到Heroku时,它会显示一条错误消息,提示“无法检测到默认语言”。 It has something to do with build packs. 它与构建包有关。 I am unable to figure it out. 我无法弄清楚。 Here is the link to my repo on GitHub: My repo on GitHub 这是我在GitHub上的仓库的链接: 我在GitHub上的仓库

Heroku supports node server so create a basic node server for your angular application Heroku支持节点服务器,因此为您的角度应用程序创建基本的节点服务器

Install NodeJS and type npm init from project folder to initialise the package.json file. 安装NodeJS并从项目文件夹中键入npm init来初始化package.json文件。 Install these packages gzippo, express, morgan. 安装这些软件包gzippo,express,morgan。 Run this command from terminal. 从终端运行此命令。

npm install --save gzippo express morgan

server.js server.js

var gzippo = require('gzippo');
var express = require('express');
var morgan = require('morgan');
var app = express();

app.use(morgan('dev'));
app.use(gzippo.staticGzip("" + __dirname + "/"));
app.listen(process.env.PORT || 5000);

Create a Procfile (remember file without any extension) 创建一个Procfile(记住没有任何扩展名的文件)

Procfile Procfile

web: node server.js

Now try deploying your branch on Heroku 现在尝试在Heroku上部署分支

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

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