Connection between two custom App Engines - google-app-engine

How do I connect between two App Engines?
I want to run a custom runtime with nginx for serving my frontend files and an other App Engine serving the backend with nodejs.
In my "one server setup" i use nginx to proxy everything from /api/ to localhost:3000 (my node instance)
I think i could start the Backend, look up the internal ip and proyx to that but i'd guess thats not the right way and it wouldn't allow me to test locally with gcloud app run.

Related

Does npm server is necessary for ReactJS with django on production?

I have developped the application with DJango + ReactJS
when in developpment,
using
$python manage.py runserver
and
$yarn start
which launche the two servers on localhost:8000 and localhost:3000
However in production environment, I need to launch two servers??
When I use webpack before I run two server in developpment environment, but in Production just building in advance and use only on one server uwsgi
Could run under one server directly, I'll share other ways too.
Have your yarn build done and serve under Django's static files + listen for js/css/image assets. Now about your routing, you need to capture frontend routes such a way that (when direct url is entered), Django responds back static assets itself.
The downside in above is that your APIs' urls have to be following some pattern which won't interfere frontend URIs (routes).
Running two servers + CORS
Pack your react build with expressjs and serve it with some production grade server like pm2/ could use nginx + static files too but to tackle routes issue (of React), you'll need to tweak nginx to listen to not only "/" but also other routes in frontend.
Now, calling django APIs, do enable CORS config to support calling APIs from your React site.
Can also use serverless to send your static files + CORS behind the scenes.
If you're not having access to root of server, would need extra one to spare in former case. Otherwise to spin up a frontend + backend process in same server machine won't do much weight.
Good luck!

How to force HTTPS with create-react-app on heroku

I'm running a very basic react app on Heroku and would like to force https on the production server, while still running localhost on https. I cannot for the life of me figure out how to do this on Heroku.
SSL and domain has been setup and works fine when I manually enter https:// before the domain. But if I manually type http:// this also works.
How do I redirect all http traffic to https for my react app on Heroko. I would like this to happen:
localhost:3000 still works in development
https is forced on production domain
create-react-app still runs without being "ejected"
Typically I'd set this up on the DNS, but Heroku only allows for a CNAME setup, so I cannot do this on the DNS level. I assume a custom server is required like express, but I cannot find any documentation on how to do this for production while stille working normally in development/localhost.

Start React app using domain instead of localhost

I start my React app using:
npm start
This starts the app on localhost:3000
I would like to have it start with a domain instead of localhost. When testing locally, I have a local domain (example mydomain.com) set to IP address 127.0.0.1. This allows me to use the actual domain in code when making requests to the backend. Without this, my code would need to support both localhost and my domain and swap them out in production.
npm start is only a command to run your react app in development mode.. for faster build and publish functionalities..
So for production, you will be using npm build to get a production build for the same. This won;t be automatically deplyed or hosted on your localhost:3000.
So production deployment you will have to host your compiled build files using IIS or some hosting application. There you can configure your preferred DNS, whcihever domain name you would want to use.
You can customise the url for deployment for development.
In your .env.development add this line
HOST='mydomain.com'
If you want to deploy at https, add this line also in same file
HTTPS=true

Google App Engine - Hosting project and website on same server

I have a NodeJs App Engine project . I also have an Apache website in another server which hosts the project dashboard. This site is the one using the node API.
I am willing to host both projects on the same server on this Google Cloud project.
Can this be achieved simply by using services in the app.yaml?
I also have an Apache website in another server which hosts the project dashboard.
What does this other server actually do? If it's serving static files, you could easily do this by adding a static_dir handler in your app.yaml
handlers:
# All URLs beginning with /dashboard are treated as paths to
# static files in the web-dashboard/ directory.
- url: /dashboard
static_dir: web-dashboard
If there is actual webserver code running, you could set up and app engine flex with a custom runtime & dockerfile to run apache
https://cloud.google.com/appengine/docs/flexible/custom-runtimes/
But an easier lift would be just rewriting your webserver code to work with one of app engines existing flex runtimes https://cloud.google.com/appengine/docs/flexible/
Once you do that, then you route traffic between the 2 services with dispatch.yaml
https://cloud.google.com/appengine/docs/standard/python/reference/dispatch-yaml

Use SSL with Dart and Managed VM's

I wish to know how I can use a secure connection (https) with Dart and Managed VM's on localhost and when it's deployed.
Thank you.
When an application is deployed using gcloud preview app deploy the default is that the App Engine application will be served on both HTTP and HTTPS. If you have an application on
http://project.appspot.com
you can access it using HTTPS on
https://project.appspot.com
If not accessing the default version the URL are:
http://version.project.appspot.com
and HTTPS on
https://version-dot-project.appspot.com
Note the first . changing to -dot-.
You can specify the following int the app.yaml to only serve the application over HTTPS:
- url: /.*
script: dummy
secure: always
This will also redirect from HTTP to HTTPS, but unfortunately not do the rewrite from . to -dot- if not using the default version.
For local development using gcloud preview app run it is not possible to use HTTPS. The following quote is from the App Engine documentation:
The development web server does not support HTTPS connections. It
ignores the secure parameter, so paths intended for use with HTTPS can
be tested using regular HTTP connections to the development web
server.
See https://github.com/dart-lang/appengine/issues/16 and https://cloud.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Secure_URLs.

Resources