美文网首页
Koa 构建 https 网站

Koa 构建 https 网站

作者: limengzhe | 来源:发表于2019-04-04 15:20 被阅读0次
    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);
    

    相关文章

      网友评论

          本文标题:Koa 构建 https 网站

          本文链接:https://www.haomeiwen.com/subject/ufxqiqtx.html