Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const HOST = opt.h || opt.host || getStHost();
const FALLINDEX = opt.f || opt.fallback || 'index.html';
const DEBUG = opt.d || opt.debug || false;
const LOCALHTTPS = opt.s || opt.https || false;
const CACHE = opt.c || opt.cache || false;
const CACHE_TTL = opt.cacheTTL || 3600;
const SSL = opt.ssl || false;
const IS_DEV = process.env.NODE_ENV !== 'production';
const app = express();
// Don't redirect if the hostname is `localhost` or `127.0.0.1`
app.use(redirectToHTTPS(LOCALHTTPS ? [] : [/localhost|127.0.0.1/]));
app.use(loggerMiddleware(DEBUG));
app.use(pupperender.makeMiddleware({debug: DEBUG, useCache: CACHE, cacheTTL: CACHE_TTL}));
app.use(express.static(ROOT));
app.use(fallback(FALLINDEX, {root: ROOT}));
const sslCert = SSL && IS_DEV ?
await certificate.default('pwa-server', {installCertutil: true}) : null;
return new Promise(resolve => {
const server = sslCert ? createServer(sslCert, app) : app;
const res = server.listen(
PORT,
HOST,
() => {
log.green('HSP started 🤘');
log.info(
`Path: ${ROOT} \nHost: ${sslCert ? 'https' : 'http'}://${HOST}:${PORT} \nFalling on: ${join(ROOT, FALLINDEX)}`
);