OpenFaaS Node.js and Express.js template
Trying the template
$ faas template pull git@gitlab.aibee.cn:dataplatform/node-faas-template.git --overwrite
$ faas new function --lang node-express
# 由于路径问题,固定项目名叫function,会生成function目录,接口后缀手动修改function.yml文件的functions
# 由于node模块问题,需在外层安装package.json,copy配置文件
$ cp template/node-express/package.json template/node-express/babel.config.js template/node-express/.eslintrc.js template/node-express/.gitignore ./
Start Development
$ npm install
# 修改 function/utils/config.yml数据库等配置
# 自动生成表模型
$ npm run model 表名
# 启动服务
$ npm start
$ npm stop
build && push && deploy
# 修改 function.yml文件
# test-faas-node 为部署到openfaas后接口后缀 http://openfaas.aibee.cn/function/test-faas-node
provider:
name: openfaas
gateway: http://openfaas.aibee.cn
functions:
test-faas-node:
lang: node-express
handler: ./function
image: registry.aibee.cn/bi-faas-web/test-faas-node:0.0.1
# 执行
faas-cli build -f ./function.yml
faas-cli push -f ./function.yml
faas-cli deploy -f ./function.yml
Config
function/utils/config.yml
env:
host: localhost:3000
prefix: ""
schedule:
# 定时任务,每10秒执行方法 service.projects.test
projects.test: "*/10 * * * *"
Example usage
Example with express HTTP API:
/** * /function/routes/label_types.js * app express router * db sequelize and all models * util wrap tools **/ { app; app;}
Service Methods:
/** * /function/service/label_types.js * db sequelize and all models * all service **/ { return service;}
Example with sequelize models:
// generate by initModels.js /* jshint indent: 1 */ module { return sequelize;};
swagger support:
/** * @swagger * definitions: * projects: * properties: * category_id: * type: string * description: 分类ID * name: * type: string * description: 项目名称 * status: * type: integer * description: 项目状态 */ /** * @swagger * /projects: * get: * tags: * - 项目管理 * description: 分页查询 * produces: * - application/json * parameters: * - name: name * description: 项目名称 * in: query * type: string * - name: page * in: query * type: integer * - name: size * in: query * type: integer * responses: * 200: * description: An array of projects * schema: * $ref: '#/definitions/projects' */
Use Technology && Help Docs
express web服务框架 express
sequelize 数据库操作ORM框架 sequelize / sequelize blog
swagger 接口文档生成器 swagger / swagger example
start with node10-express template