From 1436617aab030fa5b3760a3eeae37a1cdeeba2df Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 21 Nov 2017 03:40:09 +0900 Subject: wip --- src/web/server.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/web/server.ts') diff --git a/src/web/server.ts b/src/web/server.ts index dde4eca5ec..300f3ed477 100644 --- a/src/web/server.ts +++ b/src/web/server.ts @@ -37,28 +37,45 @@ app.use((req, res, next) => { * Static assets */ app.use(favicon(`${__dirname}/assets/favicon.ico`)); -app.get('/manifest.json', (req, res) => res.sendFile(`${__dirname}/assets/manifest.json`)); app.get('/apple-touch-icon.png', (req, res) => res.sendFile(`${__dirname}/assets/apple-touch-icon.png`)); app.use('/assets', express.static(`${__dirname}/assets`, { maxAge: ms('7 days') })); +app.get('/sw.js', (req, res) => res.sendFile(`${__dirname}/assets/sw.js`)); + /** - * Common API + * Manifest */ -app.get(/\/api:url/, require('./service/url-preview')); +app.get('/manifest.json', (req, res) => { + const manifest = require((`${__dirname}/assets/manifest.json`)); + + // Service Worker + if (config.sw) { + manifest['gcm_sender_id'] = config.sw.gcm_sender_id; + } + + res.send(manifest); +}); /** * Serve config */ app.get('/config.json', (req, res) => { - res.send({ + const conf = { recaptcha: { siteKey: config.recaptcha.siteKey } - }); + }; + + res.send(conf); }); +/** + * Common API + */ +app.get(/\/api:url/, require('./service/url-preview')); + /** * Routing */ -- cgit v1.2.3-freya