How to deploy angular 6 app on cloud foundry using node js buildpack?

Viewed 2267

I want to deploy my angular 6 app on PCF as a stand alone app using nodejs buildpack. Is there a way to do that without adding the angular universal feature to it.

If it is not possible, is there a way to read PCF user provided environment variables if I deploy my app using static buildpack?

2 Answers

It is possible to use nginx_buildpack adding an url to nginx configuration to give access to cloudfoundry environnement variables.

Using nginx.conf in the root folder of your application :

http {
  server {
    listen {{port}};    
    root public;

    location /myenv {
        return 200 '{{ env "MYENV" }}';
    }
  }
}
events {}

Pushing the application using :

cf push <myapp> -b https://github.com/cloudfoundry/nginx-buildpack.git --no-start
cf set-env <myapp> MYENV "whatever you like"
cf start <myapp>

Then you can access from the angular application to the environment variable using /myenv

To use it with Staticfile buildpack just have a folder named "public" with all your compiled js/css/html files and a file named 'Staticfile'.

Zip this folder and use this archive to push it to a pcf app.

your app
 - public <- folder
   - js
   - css
   - index.html
 - Staticfile <- file

Staticfile use nginx to serve your files and has a default nginx.conf

If you want to further customize your nginx to use features like api gateway or reverse proxying then use the nginx Buildpack.

Related