Created
May 22, 2018 07:04
-
-
Save chux0519/4a3790e6b5e7b17735c34d44a8366264 to your computer and use it in GitHub Desktop.
superstatic, etag
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
const superstatic = require('superstatic').server | |
const path = require('path') | |
const fsProvider = require('superstatic/lib/providers/fs') | |
// Remove etag, cancel the browser's cache, avoid update issues | |
function noCacheProvider (options) { | |
const handler = fsProvider(options) | |
return (req, pathname) => handler(req, pathname).then(res => { | |
if (res) { // res can be null | |
res.modified = false | |
res.etag = false | |
} | |
return res | |
}) | |
} | |
const config = { | |
'rewrites': [ | |
{'source': '/*', 'destination': 'index.html'} | |
] | |
} | |
const port = Number(process.env.PORT) || 8080 | |
const distPath = path.join(__dirname, './dist') | |
const app = superstatic({ | |
provider: noCacheProvider({cwd: distPath, ...config}), | |
port, | |
cwd: distPath, | |
config, | |
compression: true | |
}) | |
app.listen(() => { | |
console.log(`Serving on port ${port}...`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment