nodejs:使用 Koa 搭建 https Web 服务器

const Koa = require('koa');
const fs = require('fs');
const https = require('https');
const enforceHttps = require('koa-sslify');
const path = require('path');
const static = require('koa-static');

const app = new Koa();

//  证书
var options = {
    key: fs.readFileSync('./cert/limengzhe.work.key'),
    cert: fs.readFileSync('./cert/limengzhe.work.pem')
};

// 主页静态文件
const dist = static(path.join(__dirname) + '/dist/');
app.use(dist);

app.use(async ctx => {
    ctx.body = 'Hello koa'
});

https.createServer(options, app.callback()).listen(443);

你可能感兴趣的:(nodejs:使用 Koa 搭建 https Web 服务器)