How to deploy yoman build to aws node.js

I am new to yoman and trying to get a basic site created by yoman that was deployed on an elastic beanstalk. The moment I deploy, I get 502: Bad Gateway. I can deploy a simple nodejs aws application with something like

server.js

var http = require("http"); http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(process.env.PORT || 8888); 

Without specifying a port in the url, this page works fine. Not sure if this applies to this issue.

The process of using the yoman angular generator is pretty standard, i.e.

 yo angular yo angular:controller testController ..add some directives / views etc.. grunt server -- serves up pages correctly on port 9000 grunt -- which creates the dist folder 

At this stage, I work with the corner application locally, from here I follow the same workflow that correctly used the previous hello world sample (commit to git repo, create an image using elastic beanstalk cli ....). I made a repo based on the contents of the / dist folder and deployed it where I got 502.

There are two conclusions that I have here, firstly, I should listen to port 80, although my previous sample: 8888 worked, so I believe that the following requirement is most relevant, that the file named server.js is in the root directory.

The output from the grunt \ dist assembly contains:

 bower_components views styles scripts 25e920e4.modules.js 5e188624.scripts.js 76c21dca.plugins.js 

So I'm not sure about the next step. I noticed that app.js is not part of the dist output, but now I have these 3 new js script files. What do I need to configure for the nodejs container to serve this new structure?

Here is the original app.js

 'use strict'; angular.module('nodealphaApp', []) .config(function ($routeProvider) { $routeProvider .when('/', { templateUrl: 'views/main.html', controller: 'MainCtrl' }) .otherwise({ redirectTo: '/' }); }); 

Let me know if I can provide more information.

Hooray!

+4
source share
2 answers

I had the exact same problem! They really want you to use grunt buildcontrol , but there is no way for AWS. grunt buildcontrol clicks on the remote control, not how the Elastic Beanstalk unfolds.

When you enter eb deploy it will deploy everything in the .git directory, not just the dist/ directory. My job was to create a local git repository in dist/ .

  • Delete all files with elastic bean stack in the repo. FYI, they are hidden.
  • Using a terminal, cd dist/ from the project root folder.
  • Run git init to create a local git repository.
  • Make an initial commit because dist/ has always been .gitignore -d.
  • Run eb init , eb create , eb deploy normally within dist/ .
  • Set your environment variables if you need them; your application does not.
  • eb open , fingers crossed.
+1
source

Here is an example Angular Nodejs template: https://github.com/joshdmiller/ng-boilerplate

Perhaps you should check the Grunt configuration file if the port matches. In your Gruntfile.js you will have port 9000 and the Nodejs code that you are listening on 8888. So change one of the two so that they have the same port.

Take a look at:

 grunt.registerTask('server', function (target) { 

it will perform some tasks and in one of the tasks (possibly "open") the port number from the Grunt configuration will be used. Cm

  grunt.initConfig({ ... 

Hope this helps you.

0
source

Source: https://habr.com/ru/post/1497897/


All Articles