如何部署 yeoman angular-fullstack 项目?

how to deploy yeoman angular-fullstack project?

我想部署一个简单的 angular 项目,使用 angular 全栈制作。

https://github.com/DaftMonk/generator-angular-fullstack

我试过了:

yo angular-fullstack test

grunt build

然后,在 dist 中我得到了 2 个文件夹:server 和 public。

如何在 linux 服务器上部署它们?

与 forever/node 和 nginx ??? 我想自行托管我的项目。

谢谢

安装generator-angular-fullstack:

npm install -g generator-angular-fullstack

新建一个目录,cd放入其中:

mkdir my-new-project && cd $_

运行 yo angular-fullstack,可选择传递应用程序名称:

yo angular-fullstack [app-name]

运行 grunt 用于构建,gruntserve for preview, andgrunt serve:dist` 用于预览构建的应用程序

1.) 安装nginx

2.) 代理将 nginx 转发到您的节点端口。参见 Digital Oceans How-To

nginx.conf

 server {
    listen       80;
    server_name  localhost;

    location / {
                 proxy_pass http://localhost:9000;
                 proxy_http_version 1.1;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection 'upgrade';
                 proxy_set_header Host $host;
                 proxy_cache_bypass $http_upgrade;
    }
}

3.) 启动 app.js 并在 dist 文件夹中使用正确的变量启动节点:

$ export NODE_ENV=production; export PORT=9000; node dist/server/app.js

4.) 浏览到步骤 2 中在 nginx 中配置的主机名

如果你得到很多 404,你很可能在 HTML5 模式下使用 angular.js并且需要重新连接您的路由以提供静态 angular.js 内容。我在我的博客文章“Continous Integration with Angular Fullstack”.

中描述了这一点以及如何解决您可能遇到的许多其他错误。

您也可以试试 pm2,它简单明了,而且有很多有用的功能。

https://github.com/Unitech/pm2

// Start new node process
$ pm2 start dist/server/app.js

// list all process
$ pm2 list

此外,如果您 运行 将 mongo 数据库与主机连接,您将需要更改 /server/config/environment/production.js uri 以匹配 development.js 并且它应该可以。

使用 MongoLab,您可以实现以下效果: mongodb://user:pass@XXXXX.mongolab.com:XXXXX/yourdatabase

然后 运行 g运行t serve:dist 命令在您的应用程序目录中。

这对我有用。