question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Express router issue when using a custom domain name

See original GitHub issue

Hi, I am using aws-serverless-express for exposing the express router endpoints. The endpoints work when the generated API gateway is used as it is. e.g https://711111abcde.execute-api.ap-southeast-2.amazonaws.com/dev/health. But after mapping this hostname to a custom domain (https://api.myapp.com), the endpoints do not work. The same custom domain endpoints work when the lambdas are not in express app.

My Code:

const app = express();
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(awsServerlessExpressMiddleware.eventContext())

app.get('/health', (req, res) => {
  console.log('APP health1: ');
  res.status(200).json({ status: 'Next() API Health is OK and now ready to process requests...' });
});

The custom domain gives the headers as "x-powered-by’ : express. This says that my requests hit the express app but somehow never routed to any of the endpoints configured.

const awsServerlessExpress = require('aws-serverless-express');
const route = require('./route');
const server = awsServerlessExpress.createServer(route);
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);

Are there any more configuration needed for custom domain (API Gateway). Please advise

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
muswaincommented, Aug 17, 2018

@Mohan1996 - You can do the following:

  • Get the @turinggroup/serverless-express-custom-domain-middleware npm package
  • Then use it in your route.js or whichever file you are using for configuring your express routers const customDomainReroute = require('@turinggroup/serverless-express-custom-domain-middleware').customDomainReroute const app = express(); app.use(customDomainReroute)

Rest of the code is as it is used in any express route js. The above npm package helps in resolving the basePath that has been setup in API GW for a custom API domain (e.g https://api.myapp.com)

0reactions
brettstackcommented, Aug 18, 2018

Closing in favor of #86

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express router issue when using a custom domain name #153
Hi, I am using aws-serverless-express for exposing the express router endpoints. The endpoints work when the generated API gateway is used ...
Read more >
Is there anyway to use a custom domain in Express.js
Your domain needs to be hooked up to the public IP address of your server. That IP address needs to be accessible from...
Read more >
How to implement a custom domain feature with Express.js
Configuring your domain. Navigate to your DNS provider and add “A record” pointing to your server ip address. For example, if your domain...
Read more >
Routing - Express.js
Route parameters are named URL segments that are used to capture the values specified at their position in the URL. The captured values...
Read more >
A (Re)Introduction to Express.js Routes - Jordan Kasper
Let's start off with a simple Express route handler: ... This is called a URL parameter, and is easily specified, but will require...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found