feat: 100 times cache time for wrong path
This commit is contained in:
parent
57431346bd
commit
f7d9688a62
|
|
@ -2,11 +2,15 @@ const he = require('he');
|
|||
const mercury_parser = require('@postlight/mercury-parser');
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
const config = require('@/config').value;
|
||||
|
||||
module.exports = async (ctx, next) => {
|
||||
await next();
|
||||
|
||||
if (!ctx.state.data && !ctx._matchedRoute) {
|
||||
ctx.set({
|
||||
'Cache-Control': `public, max-age=${config.cache.routeExpire * 100}`,
|
||||
});
|
||||
throw Error('wrong path');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ const server = require('../../lib/index');
|
|||
const request = supertest(server);
|
||||
const Parser = require('rss-parser');
|
||||
const parser = new Parser();
|
||||
const config = require('../../lib/config').value;
|
||||
|
||||
afterAll(() => {
|
||||
server.close();
|
||||
|
|
@ -132,6 +133,7 @@ describe('wrong_path', () => {
|
|||
it(`wrong_path`, async () => {
|
||||
const response = await request.get('/wrong');
|
||||
expect(response.status).toBe(404);
|
||||
expect(response.headers['cache-control']).toBe(`public, max-age=${config.cache.routeExpire * 100}`);
|
||||
expect(response.text).toMatch(/Error: wrong path/);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue