【问题标题】:how to deploy yeoman angular-fullstack project?如何部署 yeoman angular-fullstack 项目?
【发布时间】:2015-04-29 09:09:07
【问题描述】:

我想部署一个用 angular fullstack 制作的简单 angular projet。

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

我试过了:

yo angular-fullstack test

grunt build

然后,在 dist 我有 2 个文件夹:server 和 public。

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

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

谢谢

【问题讨论】:

    标签: angularjs node.js nginx yeoman yo


    【解决方案1】:

    安装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` 用于预览构建的应用程序

    【讨论】:

      【解决方案2】:

      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.) Start app.js 使用 dist 文件夹中的 node 并使用正确的变量:

      $ 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”中描述了这一点以及如何解决您可能面临的许多其他错误。

      【讨论】:

        【解决方案3】:

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

        https://github.com/Unitech/pm2

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

        【讨论】:

          【解决方案4】:

          此外,如果您在主机上运行 mongo db,则需要更改 /server/config/environment/production.js uri 以匹配 development.js,它应该可以工作。

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

          然后在您的应用目录中运行 grunt serve:dist 命令。

          这对我有用。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-05-18
            • 1970-01-01
            • 2016-10-23
            • 1970-01-01
            • 1970-01-01
            • 2016-06-18
            • 1970-01-01
            • 2015-03-23
            相关资源
            最近更新 更多