httpbus

1.0.1 • Public • Published

httpbus

http bus server, Nginx-like programmable package

Installation

npm install httpbus

example

import * as path from 'path'
import * as http from 'http'
import * as net from 'net'
import { HttpBus } from 'httpbus'

const socketPath = path.join(__dirname,'test.sock')
const httpBus = new HttpBus(function (req:http.IncomingMessage):net.NetConnectOpts {
    if(req.url==='/socket' || req.headers['go-socket']==='true') {
        return {
            path:socketPath
        }
    } else {
        return {
            port:9000
        }
    }
})
httpBus.listen(8000)


const portHttp = http.createServer((req,res)=>{
    res.end('there is port')
}).listen(9000)

const socketHttp = http.createServer((req,res)=>{
    res.end('there is socket')
}).listen(socketPath)

Package Sidebar

Install

npm i httpbus

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

5.26 kB

Total Files

7

Last publish

Collaborators

  • zy445566