Skip to content

Commit

Permalink
chore: Upgrade to fastify@3
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Dropped support for fastify v2. Please upgrade your projects to fastify v3 or use v2 of this module.
  • Loading branch information
marcbachmann committed Feb 18, 2021
1 parent 3f8d707 commit 903713b
Show file tree
Hide file tree
Showing 3 changed files with 1,009 additions and 1,490 deletions.
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function webpackPlugin (fastify, opts) {
if (!rep.context.config.static) return done()

req.cdnUrl = req.headers['x-cdn-url'] || defaultCdnUrl
const etag = etagCache.get(`${req.cdnUrl}${req.req.url}`)
const etag = etagCache.get(`${req.cdnUrl}${req.raw.url}`)
if (!etag) return done()

rep[ETagCached] = etag
Expand All @@ -94,7 +94,7 @@ async function webpackPlugin (fastify, opts) {
}

if (rep.context.config.static && !rep[ETagCached]) {
etagCache.set(`${req.cdnUrl}${req.req.url}`, etag)
etagCache.set(`${req.cdnUrl}${req.raw.url}`, etag)
}
if (req.headers['if-none-match'] === etag) rep.code(304)
done()
Expand Down Expand Up @@ -151,7 +151,7 @@ async function webpackPlugin (fastify, opts) {
if (err) throw err

let hasCompiled = false
const compiled = new Promise((resolve, reject) => {
const compiled = new Promise((resolve) => {
fastify.webpack.compiler.hooks.afterEmit.tap('WebpackDevMiddleware', (compilation) => {
if (!hasCompiled) resolve()
hasCompiled = true
Expand All @@ -162,9 +162,9 @@ async function webpackPlugin (fastify, opts) {
})
})

fastify.use((req, reply, next) => {
if (hasCompiled) return next()
compiled.then(() => next())
fastify.addHook('onRequest', async () => {
if (hasCompiled) return
await compiled
})
})
}
Expand Down Expand Up @@ -275,7 +275,7 @@ async function webpackPlugin (fastify, opts) {
}

const plugin = fp(webpackPlugin, {
fastify: '2.x',
fastify: '3.x',
name: '@livingdocs/fastify-webpack'
})

Expand Down
Loading

0 comments on commit 903713b

Please sign in to comment.