이 코드를 module.exports에서 가져올 수 있습니까?노드 js 오류 가져 오기
저는 노드 js와 js에서 꽤 새로 왔습니다. 이 코드는 내가 내보낼 수있는 방법 다른 경로
cache = (duration) => {
return (req, res, next) => {
let key = '__express__' + req.originalUrl || req.url
let cachedBody = mcache.get(key)
if (cachedBody) {
res.send(cachedBody)
return
} else {
res.sendResponse = res.send
res.send = (body) => {
mcache.put(key, body, duration * 1000);
res.sendResponse(body)
}
next()
}
}
}
에 사용될 수 있음을 원하는?
나는이었다 같은 :
module.export = {
cache: function(duration) {
return (req, res, next) => {
let key = '__express__' + req.originalUrl || req.url
let cachedBody = mcache.get(key)
if (cachedBody) {
res.send(cachedBody)
return
} else {
res.sendResponse = res.send
res.send = (body) => {
mcache.put(key, body, duration * 1000);
res.sendResponse(body)
}
next()
}
}
}
}
을하지만 GET 요청에서 사용하려고 할 때 :
는 또한module.exports = cache = (duration) => {
return (req, res, next) => {
let key = '__express__' + req.originalUrl || req.url
let cachedBody = mcache.get(key)
if (cachedBody) {
res.send(cachedBody)
return
} else {
res.sendResponse = res.send
res.send = (body) => {
mcache.put(key, body, duration * 1000);
res.sendResponse(body)
}
next()
}
}
}
내가 시도
var expCache = require('../../middleware/cache');
router.get('/:sid/fe',expCache.cache(3000),function(req,res) {
그것은 제공 :
를TypeError: expCache.cache is not a function
당신이
expCache.cache
호출 할 수 기대하는 경우
안부
* for for git *? 죄송합니다, 여기 자식은 어디 있습니까? –