Express router issue when using a custom domain name
See original GitHub issueHi, 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:
- Created 5 years ago
- Comments:8
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Mohan1996 - You can do the following:
@turinggroup/serverless-express-custom-domain-middleware
npm packageconst 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)
Closing in favor of #86