This package has been deprecated

Author message:

this package has been deprecated

listen-one

1.0.5 • Public • Published

在一个端口监听http和https

安装

npm install listen-one --save

使用

"use strict";
var express = require('express');
var app = new express();
var one = require('../index');
 
// 下载https证书的链接
app.get('/cert', function (req, res, next) {
    var cert = one.getCert();
    if (cert) {
        if (cert.header) {
            res.set(cert.header);
        }
        res.send(cert.body);
    }
});
 
app.get('/', function (req, res) {
    res.send('Hello World');
});
 
one.createServer(app);
 
// 使用https链接
one.https();
 
one.listen(3000, function (err) {
    if (err) {
        console.log(err);
    } else {
        console.log('Start Server At   http://localhost:3000/')
    }
});
 

koa2使用示例见文件test/koa.test.js

api

  • createServer(listener) : 创建服务器,同http.createServer
  • listen(port,[callback]) : 监听端口
    • port: 监听端口
    • callback: 启动监听后回调
  • https([conf]) : 启动https服务,必须在createServer之后才可以调用
    • conf: 包括key和cert,https访问的密匙和公匙
    • callback: 启动监听后的回调
  • getCert() : 获取https证书(浏览器访问地址需要证书才可正常访问)
  • close() : 停止监听端口

todo

  • 启动http
  • 启动https
  • 下载https证书
  • 停止监听端口
  • express使用示例
  • koa使用示例
  • 停止监听时停止所有服务监听
  • 增加debug调试内容

history

  • 1.0.5修复close后http和https服务器未关闭问题

Readme

Keywords

none

Package Sidebar

Install

npm i listen-one

Weekly Downloads

2

Version

1.0.5

License

MIT

Last publish

Collaborators

  • laomu