node
node
我是逗逼
这个作者很懒,什么都没留下…
展开
-
koa 运用 joi 实现 接口一致性检
import Koa from 'koa';import Joi from 'joi';import Router from '@koa/router';import validateSchemaJoi from './middlewares/schema.js';const app = new Koa();const router = new Router();const loginSchema = Joi.object({ a: Joi.string() .min(3)原创 2021-11-04 18:20:55 · 517 阅读 · 0 评论 -
数据交换之中介者模式
export default class DataMediator { constructor() { this.store = new Map(); } notify(sender, event, data = undefined) { let res; if (sender && event) { switch (event) { case 'get': res = this.get(sender);原创 2021-11-04 11:50:38 · 171 阅读 · 0 评论 -
对象类型深层次属性的获取并且能够自定义空状态的返回值
function switchEmpty(caseValue) { let resValue; switch (caseValue) { case 'undefined': resValue = undefined; break; case 'null': resValue = null; break; case 'number': resValue = 0; break; case 'ob原创 2021-11-04 11:37:21 · 187 阅读 · 0 评论 -
node express 使用 Sequelize 操作数据库(2021-5-23)
mysql 链接配置文件const conf = { database: 'node', user: 'root', password: 'xxxxx', options: { host: 'rm-2vcnsje1qrd9c966ago.mysql.cn-chengdu.rds.aliyuncs.com', dialect: 'mysql', define: { charset: 'utf8mb4', dialectOptions: {.原创 2021-05-23 22:08:01 · 438 阅读 · 1 评论 -
node express使用 express-auto-routes 管理路由(2021-5-23)
----app.js// auto-routes配置const autoRoutes = require('express-auto-routes')(app);autoRoutes(path.join(__dirname, './routes'));----模型(位于route目录下)exports.get = async function get(req, res, next) { // const token = req.headers['t-data'] // console.原创 2021-05-23 22:06:42 · 282 阅读 · 0 评论 -
node express使用 cors 实现跨域 (2021-5-23)
参考:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS// **** 跨域 *(废弃)***// app.all('*', function (req, res, next) {// res.header("Access-Control-Allow-Origin", "*");// res.header("Access-Control-Allow-Headers", "X-Requested-With, t-data");//原创 2021-05-23 22:05:30 · 242 阅读 · 1 评论