Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8895641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:50:05+00:00 2026-06-14T23:50:05+00:00

I have an app which is quite normal Express app – simple server logic,

  • 0

I have an app which is quite normal Express app – simple server logic, views, lots of client-side JS.
I have to do many AJAX requests. Some of them need to be secured by HTTPS protocol (some needn’t).

So, my server should work with both HTTP and HTTPS.
It should also work o both the local machine (ran with nodemon normally) and on Heroku.

As far as I understood, Heroku gives you a single port (process.env.PORT) you can listen to, and handles all requests through the proxy (so, you app is listening to this port and not bothering about the proto – right?)

So, am I getting this right – I should have some different code for dev machine and Heroku?

Like

...
app = express()
...

if process.env.NODE_ENV == 'production'
  app.listen(process.env.PORT)
else
  https = require('https')
  http = require('http')
  http.createServer(app).listen(5080) # some local port
  options = {
    key: fs.readFileSync('key.pem'), 
    cert: fs.readFileSync('cert.pem') # my self-signed files
  }
  https.createServer(options, app).listen(5443) # some different local port

Is it the proper way to deal with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:50:06+00:00Added an answer on June 14, 2026 at 11:50 pm

    Well, community looks quite dead these days (hope I’m wrong)

    The answer is:

    a) yes, this is the way to deal with it

    b) the way to check if you are in secure mode or not depends on the environment as well:

    if process.env.NODE_ENV == 'production'
      is_secure = (req) ->
        req.headers['x-forwarded-proto'] == 'https'
    else
      is_secure = (req) -> req.secure
    

    ADD
    If you wish to force HTTPS:

    redirect_to_https = (req, res, next) ->
      if not is_secure(req)
        res.redirect config.SECURE_DOMAIN + req.url
      else
        next()
    
    app
      .use(redirect_to_https)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app which is quite huge. It has tons of images and
I have an app which requires downloading image asynchronously in base64 encoded string(server is
I have an app which connects to xml generated by server. I would like
I'm currently writing a client-side javascript app which performs image manipulation. Some of the
I have an app which im developing for quite some time. I am experiencing
I have an app which downloads images from a server, stores them on the
I have an app which acts almost like a daemon. Sometimes it quits on
I have app in which i have recorded sound files i want that i
I have a app which will download a file from web. The download action
I have an app which has a map and some POI on it. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.