![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
egg.js
codeXml
web developer
展开
-
nodejs之eggjs结合cheerio爬取数据
实现的功能(同样适用于网站监控): 每隔一段时间更新一次网站数据。 1、每隔一段时间执行一次操作,所以需要建立一个定时器。 注意: 1、eggjs官方规定,定时器只能写在schedule目录下 2、cheerio模块主要负责解析html 3、使用之前需要安装 npm install --save cheerio // app > schedule > watchPage.js const cheerio = require('cheerio') module.exports =原创 2020-12-05 16:14:34 · 442 阅读 · 1 评论 -
node.js之egg提交post请求
1、新建验证中间件middleware > auth.js // auth.js module.exports = (option, app) => { return async function auth (ctx, next) { ctx.state.csrf = ctx.csrf; await next(); } } 2、注册中间件,config > config.default.js // config.default.js con原创 2020-11-29 20:54:40 · 682 阅读 · 0 评论 -
node.js之egg使用中间件屏蔽指定ip
1、middleware新建屏蔽中间件:forbidip.js module.exports = (option, app) => { return async function forbideIp (ctx, next) { // firbideip 数据可以来自数据库,也可以来自传参 var firbideip = option.forbidips, clientIp = ctx.request.ip; if (fir原创 2020-11-29 20:04:35 · 567 阅读 · 0 评论