Node.js开发 ---- http转https
来源:互联网 发布:长征是逃跑 知乎 编辑:程序博客网 时间:2024/06/05 08:02
从上周一折腾小程序
wx.request发起需要https请求
顺便给自己网站换一下证书
1.sslforfree注册申请证书(三个月有效期)
详细的步骤戳这里http://www.chinaz.com/web/2016/0216/504896.shtml
2.下载
密钥 private.key
证书 certificate.crt
3.app.js
var app = require('express')();var fs = require('fs');var http = require('http');var https = require('https');var privateKey = fs.readFileSync('./keys/private.key', 'utf8');var certificate = fs.readFileSync('./keys/certificate.crt', 'utf8');var credentials = {key: privateKey, cert: certificate};var httpServer = http.createServer(app);var httpsServer = https.createServer(credentials, app);var PORT = 18080;var SSLPORT = 443;httpServer.listen(PORT, function() { console.log('HTTP Server is running on: http://localhost:%s', PORT);});httpsServer.listen(SSLPORT, function() { console.log('HTTPS Server is running on: https://localhost:%s', SSLPORT);});// Welcomeapp.get('/', function(req, res) { if(req.protocol === 'https') { res.status(200).send('Welcome https!'); } else { res.status(200).send('Welcome http!'); }});
4.that is all
http://www.jianshu.com/p/853099ae2edd
http://blog.fens.me/nodejs-https-server/
0 0
- Node.js开发 ---- http转https
- Node.js配置支持https和http
- Node.js开发入门—HTTP文件服务器
- Node.js开发入门—HTTP文件服务器
- Node.js HTTP开发遇到的若干问题
- Node.js HTTP开发遇到的若干问题
- node.js 创建 https 服务器
- node.js搭建https代理服务器
- node.js 创建 https 服务器
- node.js搭建https服务
- Node.js HTTP服务器
- Node.js HTTP客户端
- node.js学习(HTTP)
- Node.js Http 介绍
- node .js 学习 http
- node.js http服务
- node.js http
- Node.js HTTP模块
- 大数据学习笔记之二十六 HDFS Hadoop File System
- EF异常‘在创建模型,此时不可使用上下文。如果在 OnModelCreating 方法内使用上下文或如果多个线程同时访问同一上下文实例,可能引发此异常。 请注意不保证 DbContext 的实例成员’
- 剑指Offer——知识点储备--Linux基本命令+Makefile
- python基于PIL和tesseract的验证码识别
- 网页设计初探
- Node.js开发 ---- http转https
- mysql中You can't specify target table for update in FROM clause错误
- 怎么用Dos命令 拷贝(覆盖)文件原文件
- ajax
- Arcgis Server10.2.2地图服务在Arccatalog切图具体步骤
- 3.2使用conda安装theano环境
- 加密函数crypt
- 判断Android APP是否在前台运行
- hdu 1010 Tempter of the Bone (dfs)