-
-
Notifications
You must be signed in to change notification settings - Fork 380
feat(middleware): add content
option (options.content.filter
, options.content.transform
)
#336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,18 @@ module.exports = function wrapper(context) { | |
} catch (e) { | ||
notFound = true; | ||
} | ||
const currentRequest = Object.assign({}, { | ||
url: req.url, | ||
method: req.method, | ||
headers: req.headers, | ||
filename, | ||
notFound | ||
}); | ||
if (context.options && context.options.content && context.options.content.filter) { | ||
if (!context.options.content.filter(currentRequest)) { | ||
return goNext(); | ||
} | ||
} | ||
if (notFound) { | ||
return resolve(goNext()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: why is it that every other "goNext" is a regular return but this one is a return resolve(goNext())? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question but I don't know the answer, try to remove the |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,42 @@ describe('Server', () => { | |
}); | ||
}); | ||
|
||
describe('filters', () => { | ||
before((done) => { | ||
app = express(); | ||
const compiler = webpack(webpackConfig); | ||
instance = middleware(compiler, { | ||
stats: 'errors-only', | ||
content: { | ||
filter(currentRequest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
let result = true; | ||
if (/.js$/.test(currentRequest.filename)) { | ||
result = false; | ||
} | ||
return result; | ||
} | ||
}, | ||
logLevel, | ||
publicPath: '/public/' | ||
}); | ||
app.use(instance); | ||
listen = listenShorthand(done); | ||
}); | ||
after(close); | ||
|
||
it('GET request to bundle file with /.js$/ filtered', (done) => { | ||
request(app).get('/public/bundle.js') | ||
.expect(404, done); | ||
}); | ||
|
||
it('request to image with /.js$/ filtered', (done) => { | ||
request(app).get('/public/svg.svg') | ||
.expect('Content-Type', 'image/svg+xml; charset=UTF-8') | ||
.expect('Content-Length', '4778') | ||
.expect(200, done); | ||
}); | ||
}); | ||
|
||
describe('no index mode', () => { | ||
before((done) => { | ||
app = express(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const currentRequest
=>const request
(we don't have different/multiple request(s) in this context)