pwa.js
864 Bytes
const path = require('path');
const _ = require('lodash');
const request = require('request');
const config = global.yoho.config;
module.exports = {
sw(req, res) {
if (req.hostname === 'activity.yoho.cn') {
return res.status(404).end();
}
res.set({
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: (new Date(1900, 0, 1, 0, 0, 0, 0)).toUTCString()
});
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'));
}
},
manifest(req, res) {
res.sendFile(path.join(__dirname, '../../../public/static/manifest.json'));
}
};