This commit is contained in:
syuilo 2018-04-13 09:44:00 +09:00
parent 61f21594a9
commit 22d2f2051c
10 changed files with 40 additions and 26 deletions

View file

@ -13,6 +13,11 @@ import sendDriveFile from './send-drive-file';
const app = new Koa();
app.use(cors());
app.use(async (ctx, next) => {
ctx.set('Cache-Control', 'max-age=31536000, immutable');
await next();
});
// Init router
const router = new Router();
@ -27,7 +32,7 @@ router.get('/app-default.jpg', ctx => {
});
router.get('/:id', sendDriveFile);
router.get('/:id/:name', sendDriveFile);
router.get('/:id/*', sendDriveFile);
// Register router
app.use(router.routes());

View file

@ -83,12 +83,6 @@ export default function(readable: stream.Readable, type: string, ctx: Koa.Contex
ctx.set('Content-Disposition', 'attachment');
}
ctx.set('Cache-Control', 'max-age=31536000, immutable');
ctx.set('Content-Type', data.contentType);
data.stream.pipe(ctx.res);
data.stream.on('end', () => {
ctx.res.end();
});
ctx.body = data.stream;
}