Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

https with express

const fs = require('fs');
const https = require('https');

const app = require('express')();
app.get('*', (req, res) => res.send('<h1>Hello, World</h1>'));

const server = https.createServer({
  key: fs.readFileSync(`${__dirname}/localhost-key.pem`, 'utf8'),
  cert: fs.readFileSync(`${__dirname}/localhost.pem`, 'utf8')
}, app);

await server.listen(443);
Comment

http to https express js

var app = express();

app.all('*', function(req, res, next){
    console.log('req start: ',req.secure, req.hostname, req.originalurl, app.get('port'));
    if (req.secure) {
        return next();
    }

    res.redirect('https://'+req.hostname + ':' + app.get('secPort') + req.originalurl);
});
Comment

express http to https

var express = require('express');var app = express(); var redirectToHTTPS = require('express-http-to-https').redirectToHTTPS // Don't redirect if the hostname is `localhost:port` or the route is `/insecure`app.use(redirectToHTTPS([/localhost:(d{4})/], [//insecure/], 301)); app.get('/', function (req, res) {  res.send('Hello World!');}); app.get('/insecure', function (req, res) {  res.send('Dangerous!');}); app.listen(3000, function () {  console.log('Example app listening on port 3000!');}); app.listen(8080, function () {  console.log('Example app listening on port 8080 insecurely!');});
Comment

PREVIOUS NEXT
Code Example
Javascript :: add text to string javascript 
Javascript :: get Two digit number js 
Javascript :: javascript change color of text input 
Javascript :: how to filter out undefined keys from object in js 
Javascript :: how to get decimal value in js 
Javascript :: firestore update array 
Javascript :: bootstrap datepicker options 
Javascript :: js Float32Array to percentage 
Javascript :: jquery change tabs 
Javascript :: dynamic loop variable .each create hash javascript 
Javascript :: javascript in keyword 
Javascript :: nodejs buffer.from base64 
Javascript :: es6 iife 
Javascript :: docker daemon bind to host and port 
Javascript :: json limit nodejs 
Javascript :: pipe data to json angular 
Javascript :: How to Use the toLowerCase() String Method in javascript 
Javascript :: javascript get all methods of class 
Javascript :: c# print object to json 
Javascript :: push array javascript 
Javascript :: js arithmetic operators 
Javascript :: js different 
Javascript :: set in javascript 
Javascript :: how we link external js file in laravel 9 project 
Javascript :: bootstrap dropdown doesnt work with angular 12 
Javascript :: nodejs import instead of require 
Javascript :: hashing in node js 
Javascript :: how to check platform in nodejs 
Javascript :: Update multiple documents by id set. Mongoose 
Javascript :: toastify 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =