feat: 100 times cache time for wrong path

This commit is contained in:
DIYgod 2019-09-20 15:24:49 +08:00
parent 57431346bd
commit f7d9688a62
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
2 changed files with 6 additions and 0 deletions

View File

@ -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');
}

View File

@ -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/);
});
});