How do you force express on node.js in Azure Websites to use https?

Curyous

Running on Windows Azure Websites, I want to use ssl via the default *.azurewebsites.net certificate. It works without doing anything, but http is also available for every destination, not just https. How do I force a redirect from http to https? Normally I could just do something like:

var https = require('https');

...

var options = {
      key: fs.readFileSync('path.key'),
      cert: fs.readFileSync('path.crt')
    };

...

https.createServer(options, app)

but since I don't know anything about the *.azurewebsites.net certificate, such as its path, that's not going to work.

How do I redirect all or some requests to https?

Curyous

In web.config, add the following rule before any other rule that has stopProcessing="true".

<rule name="RedirecttoHTTPS">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    <add input="{URL}" pattern="/$" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  </conditions>
  <action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
</rule>

You can also just use the normal http.createServer(app) for production if you want to the *.azurewebsite.net wildcard certificate.

References:

  1. How to require SSL in IIS7 and Azure with Rewrite
  2. URL Rewrite Module Configuration Reference

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do you force express on node.js in Azure Websites to use https?

From Dev

How do I setup a background process on a express.js app hosting on Azure websites?

From Dev

How do you use several request handler in node.js?

From Dev

How to use HTTPS on Node.js using Express/Socket.io

From Dev

How to force http instead of https in DocumentDB Node.js SDK

From Dev

How do you set up pretty-error module with a node.js Express app?

From Dev

How to use HTTPS with Node.js

From Dev

How do I force ASP.NET app to use HTTPS?

From Dev

how to use Promise with express in node.js?

From Dev

How to use jsonp with node.js express

From Dev

How do you use force adb to backup without user confirmation?

From Dev

How do you use force adb to backup without user confirmation?

From Dev

How to pipe upload stream of large files to Azure Blob storage via Node.js app on Azure Websites?

From Dev

How to force https redirect on heroku with express 4.0?

From Dev

How do I use a self signed certificate for a HTTPS Node.js server?

From Dev

How do you password protect static assets in Node/Express?

From Dev

How do you handle api version in a Node/Express app

From Dev

Slow HTTPS request with Node JS and Express JS?

From Dev

Preventing Brute Force Using Node and Express JS

From Dev

How do you use an HTTP/HTTPS proxy with boto3?

From Java

What is the purpose of Node.js module.exports and how do you use it?

From Dev

How do you use Node.js to stream an MP4 file with ffmpeg?

From Dev

Host multiple websites using Node.js Express

From Dev

How to use .NET framework 4.6 with Azure Websites?

From Dev

How do you use the Angular package in NodeJS and Express?

From Dev

for Azure websites, do you need to keep the awverify DNS records?

From Dev

for Azure websites, do you need to keep the awverify DNS records?

From Dev

Express (node.js) using HTTPS and HTTP

From Dev

mvc do you use model for websites with only static pages

Related Related

  1. 1

    How do you force express on node.js in Azure Websites to use https?

  2. 2

    How do I setup a background process on a express.js app hosting on Azure websites?

  3. 3

    How do you use several request handler in node.js?

  4. 4

    How to use HTTPS on Node.js using Express/Socket.io

  5. 5

    How to force http instead of https in DocumentDB Node.js SDK

  6. 6

    How do you set up pretty-error module with a node.js Express app?

  7. 7

    How to use HTTPS with Node.js

  8. 8

    How do I force ASP.NET app to use HTTPS?

  9. 9

    how to use Promise with express in node.js?

  10. 10

    How to use jsonp with node.js express

  11. 11

    How do you use force adb to backup without user confirmation?

  12. 12

    How do you use force adb to backup without user confirmation?

  13. 13

    How to pipe upload stream of large files to Azure Blob storage via Node.js app on Azure Websites?

  14. 14

    How to force https redirect on heroku with express 4.0?

  15. 15

    How do I use a self signed certificate for a HTTPS Node.js server?

  16. 16

    How do you password protect static assets in Node/Express?

  17. 17

    How do you handle api version in a Node/Express app

  18. 18

    Slow HTTPS request with Node JS and Express JS?

  19. 19

    Preventing Brute Force Using Node and Express JS

  20. 20

    How do you use an HTTP/HTTPS proxy with boto3?

  21. 21

    What is the purpose of Node.js module.exports and how do you use it?

  22. 22

    How do you use Node.js to stream an MP4 file with ffmpeg?

  23. 23

    Host multiple websites using Node.js Express

  24. 24

    How to use .NET framework 4.6 with Azure Websites?

  25. 25

    How do you use the Angular package in NodeJS and Express?

  26. 26

    for Azure websites, do you need to keep the awverify DNS records?

  27. 27

    for Azure websites, do you need to keep the awverify DNS records?

  28. 28

    Express (node.js) using HTTPS and HTTP

  29. 29

    mvc do you use model for websites with only static pages

HotTag

Archive