Skip to content
Advertisement

Heroku custom DNS API route issue in Node.js

I have a custom domain set up in Heroku which works fine. I can access my site using both my app name and custom domain. I can access a route using my standard Heroku URL, but not using the custom domain.

For example:

Works:

https://{myappname}.herokuapp.com
https://{myappname}.herokuapp.com/callback
https://{customdomain}.com

Does not work:

https://{customdomain}.com/callback

Server config:

const express = require("express");
const path = require("path");;
const callback = require("./callback");
const app = express();

// Body parser middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// Serve static assets if in production
 if (process.env.NODE_ENV === "production") {
  app.use("/callback", callback);

// Set static folder
  app.use(express.static("client/build"));

  app.get("*", (req, res) => {
   res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
 });
}

// Init server/port
const port = process.env.PORT || 5000;

app.listen(port, () => console.log(`Server running on port ${port}`));

Advertisement

Answer

I know its too late but I am writing for those who face this issue in the future.

I was also facing this issue and solved through this.

Was Not Working

https://{customdomain}.com/callback

This Worked for me.

https://www.{customdomain}.com/callback
Advertisement