devil_may_die
devil_may_die

Reputation: 61

Google AppEngine Node.js: Deploying API and WepApp

I'm new to GoogleCloud. I've followed the tutorial (for Node.js) with these steps:

  1. Build my own My-Hello-World web app
  2. Deploy to AppEngine
  3. It works fine as https://My-Hello-World.appspot.com

  4. Build my own EndPoints APIs with project-id as My-Hello-World

  5. Deploy to AppEngine
  6. It also works fine as https://My-Hello-World.appspot.com/api/test/*

My problem is the moment I deploy EndPoints APIs, my My-Hello-World.appspot.com doesn't run as webapp anymore, it responses as APIs. How to config to make my project run for both webapp and api when deploy to AppEngine?

https://My-Hello-World.appspot.com --> run as webapp

https://My-Hello-World.appspot.com/api/test/* --> run as api

Thank you.

Upvotes: 1

Views: 85

Answers (1)

M Cotter
M Cotter

Reputation: 11

So assuming that

  • Your Endpoints API and Webapp are in the same GCP project
  • Each has their own app.yaml

You can deploy them to the same project's app engine and have them run together as separate services. All you will need to do is add a service tag in your app.yaml

service: api
runtime: nodejs
env: flex

env_variables:
  NODE_ENV : staging

This is what mine looks like for a ExpressJS RestAPI that I deploy to staging.

You can keep the web-app's app.yaml the same, because it will be used as the default service.

Then you will be able to access

  • Webapp
    • https ==> my-hello-world.appspot.com
    • http ==> my-hello-world.appspot.com
  • API
    • https ==> api-dot-my-hello-world.appspot.com
    • http ==> api.my-hello-world.appspot.com

Reference

Upvotes: 1

Related Questions