2016-12-29 07:49:51 +09:00
|
|
|
/**
|
|
|
|
* File Server
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as fs from 'fs';
|
2018-04-13 06:06:18 +09:00
|
|
|
import * as Koa from 'koa';
|
|
|
|
import * as cors from '@koa/cors';
|
|
|
|
import * as Router from 'koa-router';
|
|
|
|
import sendDriveFile from './send-drive-file';
|
|
|
|
|
|
|
|
// Init app
|
|
|
|
const app = new Koa();
|
2016-12-29 07:49:51 +09:00
|
|
|
app.use(cors());
|
|
|
|
|
2018-04-13 09:44:00 +09:00
|
|
|
app.use(async (ctx, next) => {
|
2018-04-14 01:46:03 +09:00
|
|
|
// Cache 365days
|
2018-04-13 09:44:00 +09:00
|
|
|
ctx.set('Cache-Control', 'max-age=31536000, immutable');
|
|
|
|
await next();
|
|
|
|
});
|
|
|
|
|
2018-04-13 06:06:18 +09:00
|
|
|
// Init router
|
|
|
|
const router = new Router();
|
2016-12-29 07:49:51 +09:00
|
|
|
|
2018-04-13 06:06:18 +09:00
|
|
|
router.get('/app-default.jpg', ctx => {
|
2017-11-10 10:54:08 +09:00
|
|
|
const file = fs.createReadStream(`${__dirname}/assets/dummy.png`);
|
2018-05-03 20:03:14 +09:00
|
|
|
ctx.set('Content-Type', 'image/jpeg');
|
|
|
|
ctx.body = file;
|
2016-12-29 07:49:51 +09:00
|
|
|
});
|
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
router.get('/:key', sendDriveFile);
|
|
|
|
router.get('/:key/*', sendDriveFile);
|
2017-11-06 15:39:16 +09:00
|
|
|
|
2018-04-13 06:06:18 +09:00
|
|
|
// Register router
|
|
|
|
app.use(router.routes());
|
2016-12-29 07:49:51 +09:00
|
|
|
|
|
|
|
module.exports = app;
|