Created
September 17, 2017 21:55
-
-
Save andreasvirkus/5046f369274c875e681654bb49e396e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const serve = (path, cache) => express.static(resolve(path), { | |
maxAge: cache && isProd ? 60 * 60 * 24 * 30 : 0 | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage | |
import { serve } from './express-serve-static.js' | |
const fs = require('fs') | |
const path = require('path') | |
const express = require('express') | |
const favicon = require('serve-favicon') | |
const compression = require('compression') | |
const app = express() | |
const port = process.env.PORT || 8080 | |
const isProd = process.env.NODE_ENV === 'production' | |
app.use(compression({ threshold: 0 })) | |
app.use(favicon('./public/logo.png')) | |
app.use('/service-worker.js', serve('./dist/service-worker.js')) | |
app.use('/manifest.json', serve('./manifest.json')) | |
app.use('/dist', serve('./dist')) | |
app.use('/public', serve('./public')) | |
app.listen(port, () => { | |
console.log(`server started at localhost:${port}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment