From b099ad2a30aac43c4dbe36864f9045a687cfd30b Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 13 Apr 2018 12:05:24 +0900 Subject: [PATCH] wip --- .../common/views/components/url-preview.vue | 2 +- src/client/docs/layout.pug | 2 +- src/server/web/docs.ts | 20 ++++++++++++------- src/server/web/index.ts | 4 +++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/client/app/common/views/components/url-preview.vue b/src/client/app/common/views/components/url-preview.vue index e91e51055..fd25480f6 100644 --- a/src/client/app/common/views/components/url-preview.vue +++ b/src/client/app/common/views/components/url-preview.vue @@ -45,7 +45,7 @@ export default Vue.extend({ } else if (url.hostname == 'youtu.be') { this.youtubeId = url.pathname; } else { - fetch('/api:url?url=' + this.url).then(res => { + fetch('/url?url=' + this.url).then(res => { res.json().then(info => { this.title = info.title; this.description = info.description; diff --git a/src/client/docs/layout.pug b/src/client/docs/layout.pug index 29d2a3ff6..1d9ebcb4c 100644 --- a/src/client/docs/layout.pug +++ b/src/client/docs/layout.pug @@ -6,7 +6,7 @@ html(lang= lang) meta(name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no") title | #{title} | Misskey Docs - link(rel="stylesheet" href="/assets/style.css") + link(rel="stylesheet" href="/docs/assets/style.css") block meta //- FontAwesome style diff --git a/src/server/web/docs.ts b/src/server/web/docs.ts index a546d1e88..75da01068 100644 --- a/src/server/web/docs.ts +++ b/src/server/web/docs.ts @@ -2,20 +2,26 @@ * Docs */ -import * as path from 'path'; +import ms = require('ms'); import * as Router from 'koa-router'; import * as send from 'koa-send'; -const docs = path.resolve(`${__dirname}/../../client/docs/`); +const docs = `${__dirname}/../../client/docs/`; const router = new Router(); -router.get('/assets', async ctx => { - await send(ctx, `${docs}/assets`); +router.get('/assets/*', async ctx => { + await send(ctx, ctx.path, { + root: docs, + maxage: ms('7 days'), + immutable: true + }); }); -router.get(/^\/([a-z_\-\/]+?)$/, async ctx => { - await send(ctx, `${docs}/${ctx.params[0]}.html`); +router.get('*', async ctx => { + await send(ctx, `${ctx.params[0]}.html`, { + root: docs + }); }); -module.exports = router; +export default router; diff --git a/src/server/web/index.ts b/src/server/web/index.ts index dd296f875..376aadda7 100644 --- a/src/server/web/index.ts +++ b/src/server/web/index.ts @@ -8,6 +8,8 @@ import * as Router from 'koa-router'; import * as send from 'koa-send'; import * as favicon from 'koa-favicon'; +import docs from './docs'; + const client = `${__dirname}/../../client/`; // Init app @@ -54,7 +56,7 @@ router.get('/manifest.json', async ctx => { //#endregion // Docs -router.use('/docs', require('./docs').routes()); +router.use('/docs', docs.routes()); // URL preview endpoint router.get('url', require('./url-preview'));