Skip to content

Commit 6415985

Browse files
authored
Updating getAssetName to take in req and res objects (#10)
1 parent 70ff068 commit 6415985

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ This is a prefix for Kevin's internal API. You probably don't need to change thi
106106
#### `getAssetName`
107107

108108
- Type: `Function`
109-
- Default: `path => path`
109+
- Default: `(requestPath, req, res) => requestPath.replace(/^\//, "").replace(/\.js$/, "")`
110110

111-
Given a request path, return the name of the asset we're trying to serve. Useful if you have entries that don't map to the filenames they render.
111+
Given a request path, req object, and res object, return the name of the asset we're trying to serve. Useful if you have entries that don't map to the filenames they render.
112112

113113
#### `additionalOverlayInfo`
114114

Diff for: lib/middleware.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ class Kevin {
4242
// Set to 0 to never evict anything, but that'll probably make you run out of
4343
// memory.
4444
maxCompilers = 3,
45-
// Given a request path, return the name of the asset we're trying to serve.
45+
// Given a request path, the req object, and the res object, return the name of the asset we're trying to serve.
4646
// Useful if you have entries that don't map to the filenames they render.
4747
// Default: strip off leading forward slash and js extension. This is because
4848
// the middleware will store things as `app-a/a1`, but requests will be for `/app-a/a1.js`.
49-
getAssetName = (requestPath) =>
49+
getAssetName = (requestPath, req, res) =>
5050
requestPath.replace(/^\//, "").replace(/\.js$/, ""),
5151
// Only build assets; don't handle serving them. This is useful if you want to do
5252
// something with the built asset before serving it.
@@ -348,7 +348,7 @@ class Kevin {
348348
}
349349

350350
// Mangle the url to get asset name
351-
const assetName = this.getAssetName(reqPath);
351+
const assetName = this.getAssetName(reqPath, req, res);
352352
// Select appropriate config for given asset
353353
const config = this.getConfigForAssetName(assetName, this.configs);
354354
// Bail if none are found (this path may be handled by another middleware)

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kevin-middleware",
3-
"version": "1.0.3",
3+
"version": "1.1.0",
44
"description": "This is an Express middleware that makes developing javascript in a monorepo easier.",
55
"main": "index.js",
66
"directories": {

0 commit comments

Comments
 (0)