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