Skip to content

Instantly share code, notes, and snippets.

@hsipeng
Created September 12, 2019 02:19
Show Gist options
  • Save hsipeng/eb2942fe4c51bd17f29282bc86b4100a to your computer and use it in GitHub Desktop.
Save hsipeng/eb2942fe4c51bd17f29282bc86b4100a to your computer and use it in GitHub Desktop.
本地添加https

本地添加https

https://lisongfeng.cn/post/quick-deploy-https-in-local-development-env.html

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

// This line is from the Node.js HTTPS documentation.
var options = {
  key: fs.readFileSync("./cert/lirawx.cnsuning.com.key"),
  cert: fs.readFileSync("./cert/lirawx.cnsuning.com.crt")
};

// Create a service (the app object is just a callback).
var app = express();
app.use(express.static("public"));
// Create an HTTP service.
http.createServer(app).listen(80, function() {
  console.log("Server is server over http://lirawx.cnsuning.com");
});
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(443, function() {
  console.log("Server is server over https://lirawx.cnsuning.com");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment