express-subdomain icon indicating copy to clipboard operation
express-subdomain copied to clipboard

Not working on https behind a proxy (cloudflare/heroku)

Open ferreiro opened this issue 7 years ago • 2 comments

Hi! I've the following setup:

  • Cloudflare: Which redirects api.mydomain.com to myapp.herokuapp.com
  • Heroku: Contains the Express.JS server with the express-subdomain handler.

This is how I define the express-subdomain

const subdomain = require('express-subdomain')
const express = require('express')

const app = express()

const apiRouter = express.Router()
apiRouter.use('/users', require('./users.route'))
apiRouter.use('/posts', require('./posts.route'))

app.use(subdomain('api', apiRouter))
app.use('/api', apiRouter)

Why is this not working? Any clue?

Thanks!

ferreiro avatar Nov 02 '17 15:11 ferreiro

Hmmm I think the request.url will no longer be api.mydomain.com it will now be myapp.herokuapp.com in your example.

You could configure the subdomain url via an environment variable - allowing you to give it different values in different environments.

bmullan91 avatar Nov 02 '17 15:11 bmullan91

This is how I set up https://dispensary.indospace.io/ behind an nginx proxy.

    var app = express()
    app.dispensary = express.Router()
    app.use(require('express-subdomain')('dispensary', app.dispensary))

Controller Files for dispensary.indospace.io

    app.dispensary.post('/cart-session', (req, res) => {
    })
   app.dispensary.get('/:city/:dispensary_url', (req, res) => {
   })

Controller Files for indospace.io

    app.post('/search', (req, res) => {
    })
   app.get('/', (req, res) => {
      // show homepage
   })

knoxcard avatar Apr 22 '18 06:04 knoxcard