Blame view

apps/api/controllers/pwa.js 864 Bytes
毕凯 authored
1
const path = require('path');
2 3 4
const _ = require('lodash');
const request = require('request');
const config = global.yoho.config;
毕凯 authored
5 6 7

module.exports = {
    sw(req, res) {
陈峰 authored
8 9 10
        if (req.hostname === 'activity.yoho.cn') {
            return res.status(404).end();
        }
毕凯 authored
11 12 13 14 15
        res.set({
            'Cache-Control': 'no-cache',
            Pragma: 'no-cache',
            Expires: (new Date(1900, 0, 1, 0, 0, 0, 0)).toUTCString()
        });
16 17 18 19 20 21 22
        if (_.get(res, 'app.locals.devEnv')) {
            return request({
                url: `http:${config.assetUrl}${req.originalUrl.substring(1)}`
            }).pipe(res);
        } else {
            return res.sendFile(path.join(__dirname, '../../../public/static/sw.js'));
        }
毕凯 authored
23 24 25 26 27
    },
    manifest(req, res) {
        res.sendFile(path.join(__dirname, '../../../public/static/manifest.json'));
    }
};