0.3.4 • Published 3 years ago

@domain.js/router v0.3.4

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

@domain.js/router

Domain.js 项目通用桥接 http server 模块使用到的路由功能, 基于 restify

Build status codecov

Installation

环境变量

  • PROXY_IPS 代理服务的IP, 多个用逗号分隔, 默认 127.0.0.1

Usage (sample)

const restify = require('router');
const Router = require('@domain.js/router');

const domain = {
  home: {
    async index(profile, params) {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve({ foo: 'bar' })
        }, 100);
      });
    }
  }
}
const routers = (r) => {
  r.get('/home', 'home.index')
}
const httpCodes = {
  noAuth: 401,
  notFound: 404,
  notAllowed: 403,
  tokenError: 403,
}


const server = restify.createServer();
server.use(restify.plugins.queryParser());
server.use(
  restify.plugins.bodyParser({
    keepExtensions: true,
    maxFieldsSize: 2 * 1024 * 1024 // 参数最大容量 2MB
  })
);

const router = Router(server, domain, httpCodes);
routers(router);

server.listen(
  process.env.HTTP_PORT || 8088,
  process.env.HTTP_HOST || "127.0.0.1",
  () => {
    console.log("%s listening at %s", server.name, server.url);
  }
);
0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.0

3 years ago

0.3.1

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago