express icon indicating copy to clipboard operation
express copied to clipboard

Can't set base path mapping for domain stage

Open kueckermann opened this issue 5 years ago • 4 comments

It doesnt seem to be possible to define a base path for a domain in serverless.yml. This would be great since currently, I need to do it manually.

kueckermann avatar Aug 17 '20 14:08 kueckermann

Not sure what you mean @kueckermann 🤔 ... could you clarify? How would that domain look like in serverless.yml?

eahefnawy avatar Sep 01 '20 10:09 eahefnawy

@eahefnawy before using the serverless express component we were using the standard serverless framework with functions. On that we used to use the serverless-domain-manager plugin, which allowed for defining a base path for API gateway. This was valuable because we could with the same domain and point the base path "api.example.com/dev" to our dev stage API, "api.example.com/staging" to our staging API, etc.

I could imagine it would look something like this in serverless.yml, dynamically setting the base path to the stage:

inputs:
  src: ./                        
  description: My Express App    
  domain: api.serverless.com   
  basePath: ${opt:stage}

kueckermann avatar Sep 01 '20 13:09 kueckermann

@kueckermann wouldn't it be the same if you change the subdomain according to the stage?

stage: dev # you can change this to set the stage

inputs:
  domain: ${stage}.api.serverless.com

So you'd get https://dev.api.serverless.com in dev, and https://staging.api.serverless.com in staging.

You could also set the entire domain as an env variable, and have its value stored differently for each stage .env file. So the yml file would be:


inputs:
  domain: ${env:DOMAIN}
# .env.dev

DOMAIN=dev.api.serverless.com
# .env.prod

DOMAIN=api.serverless.com

Does that help?

eahefnawy avatar Sep 04 '20 14:09 eahefnawy

Thanks @eahefnawy but it's unfortunately not the same thing. It depends on how a platform has chosen to set up their API Gateway on AWS. On API Gateway you need to define custom domain mappings for each domain, this includes for each subdomain. If your team has many stages for your API this can make a mess of API Gateway custom domains. AWS has a solution for this, base paths. On every API Gateway cusom domain you can specify to route the first portion of your URL string to a separate API Gateway. For example: api.serverless.com/dev goes to your dev stage. api.serverless.com/qa goes to your quality assurance stage.

kueckermann avatar Sep 04 '20 16:09 kueckermann