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

https express

var express = require("express");
var fs = require("fs");
var https = require("https");
var app = express();

app.get("/", function (req, res) {
  res.send("hello world");
});

https
  .createServer(
    {
      key: fs.readFileSync("server.key"),
      cert: fs.readFileSync("server.cert"),
    },
    app
  )
  .listen(3000, function () {
    console.log(
      "Example app listening on port 3000! Go to https://localhost:3000/"
    );
  });
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 :: canada postal code regex 
Javascript :: map images from folder react 
Javascript :: javascript redirect 
Javascript :: redirect to another page javascript 
Javascript :: javascript redirect to 
Javascript :: javascript document redirect 
Javascript :: redirect function in javascript 
Javascript :: js display only date 
Javascript :: get first two letter of an array javascript 
Javascript :: js sort by property 
Javascript :: javascript parentnode 
Javascript :: javascript date get minutes with leading zero 
Javascript :: reactjs link props 
Javascript :: how to wait in javascript 
Javascript :: check if input is touched react 
Javascript :: remove space from string javascript 
Javascript :: File is a CommonJS; it may be converted to an ES6 module 
Javascript :: disable unused vars 
Javascript :: json schema string or null 
Javascript :: js select disabled 
Javascript :: javascript compare two objects 
Javascript :: run react app in react 18 
Javascript :: javascript substring after character 
Javascript :: ajax authorization header token 
Javascript :: js omit last string 
Javascript :: are you sure you want to proceed click ok button javascript code 
Javascript :: find all images without alternate text 
Javascript :: refresh event in javascript 
Javascript :: vuejs scrollBehavior 
Javascript :: js read date from milliseconds 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =