Gathering detailed insights and metrics for node-faas-express
Gathering detailed insights and metrics for node-faas-express
Gathering detailed insights and metrics for node-faas-express
Gathering detailed insights and metrics for node-faas-express
npm install node-faas-express
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
$ 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 ./
$ npm install
# 修改 function/utils/config.yml数据库等配置
# 自动生成表模型
$ npm run model 表名
# 启动服务
$ npm start
$ npm stop
# 修改 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
function/utils/config.yml
env:
host: localhost:3000
prefix: ""
schedule:
# 定时任务,每10秒执行方法 service.projects.test
projects.test: "*/10 * * * *"
Example with express HTTP API:
1/** 2 * /function/routes/label_types.js 3 * app express router 4 * db sequelize and all models 5 * util wrap tools 6 **/ 7export default function(app, db, util, service) { 8 app.get("/label_types", function(req, res) { 9 db.label_types.findAll().then(data => { 10 res.json(util.wrap(data)); 11 }); 12 }); 13 14 app.post("/label_types", function(req, res) { 15 let checkData = util.checkModelData(req.body, db.label_types); 16 if (checkData) { 17 res.json(util.wrapError(checkData)); 18 return; 19 } 20 db.label_types 21 .create(req.body) 22 .then(data => { 23 res.json(data); 24 }) 25 .catch(err => { 26 res.json({ err: err }); 27 }); 28 }); 29}
Service Methods:
1/** 2 * /function/service/label_types.js 3 * db sequelize and all models 4 * all service 5 **/ 6export default function(db, service) { 7 return service.define("projects", { 8 /** 9 * 更新项目配置,同时更新日常编排任务配置 10 * @param {*} pid 11 * @param {*} params 12 */ 13 async updateProjectWithTask(pid, params) { 14 let label_configuration = params.label_configuration || {}; 15 return await db.sequelize.transaction(t => { 16 return Promise.all([ 17 db.projects.update(params, { 18 where: { id: pid }, 19 transaction: t 20 }), 21 db.daily_tasks.update( 22 { 23 assigned_group_list: label_configuration.assigned_group_list, 24 max_worker_count: label_configuration.max_worker_count 25 }, 26 { 27 where: { project_id: pid }, 28 transaction: t 29 } 30 ) 31 ]); 32 }); 33 }, 34 async test(){ 35 console.log("schedule doing"); 36 } 37 }); 38}
Example with sequelize models:
1// generate by initModels.js 2/* jshint indent: 1 */ 3 4module.exports = function(sequelize, DataTypes) { 5 return sequelize.define( 6 "label_types", 7 { 8 id: { 9 type: DataTypes.INTEGER(11), 10 allowNull: false, 11 primaryKey: true, 12 autoIncrement: true 13 }, 14 name: { 15 type: DataTypes.STRING(128), 16 allowNull: false 17 }, 18 type: { 19 type: DataTypes.STRING(128), 20 allowNull: false, 21 unique: true 22 }, 23 label_configuration: { 24 type: DataTypes.TEXT, 25 allowNull: true 26 }, 27 created_at: { 28 type: DataTypes.DATE, 29 allowNull: true, 30 defaultValue: sequelize.literal("CURRENT_TIMESTAMP") 31 }, 32 updated_at: { 33 type: DataTypes.DATE, 34 allowNull: false, 35 defaultValue: sequelize.literal("CURRENT_TIMESTAMP") 36 } 37 }, 38 { 39 tableName: "label_types", 40 timestamps: false 41 } 42 ); 43};
swagger support:
1 /** 2 * @swagger 3 * definitions: 4 * projects: 5 * properties: 6 * category_id: 7 * type: string 8 * description: 分类ID 9 * name: 10 * type: string 11 * description: 项目名称 12 * status: 13 * type: integer 14 * description: 项目状态 15 */ 16 17 /** 18 * @swagger 19 * /projects: 20 * get: 21 * tags: 22 * - 项目管理 23 * description: 分页查询 24 * produces: 25 * - application/json 26 * parameters: 27 * - name: name 28 * description: 项目名称 29 * in: query 30 * type: string 31 * - name: page 32 * in: query 33 * type: integer 34 * - name: size 35 * in: query 36 * type: integer 37 * responses: 38 * 200: 39 * description: An array of projects 40 * schema: 41 * $ref: '#/definitions/projects' 42 */
express web服务框架 express
sequelize 数据库操作ORM框架 sequelize / sequelize blog
swagger 接口文档生成器 swagger / swagger example
start with node10-express template
No vulnerabilities found.
No security vulnerabilities found.