https://github.com/kyleross/express-skip-map
Middleware for Express 3.x/4.x to skip .map files to prevent 404 errors
https://github.com/kyleross/express-skip-map
Last synced: 3 months ago
JSON representation
Middleware for Express 3.x/4.x to skip .map files to prevent 404 errors
- Host: GitHub
- URL: https://github.com/kyleross/express-skip-map
- Owner: KyleRoss
- License: mit
- Created: 2015-08-27T17:04:07.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-08-27T17:36:16.000Z (almost 11 years ago)
- Last Synced: 2024-10-30T00:43:46.364Z (over 1 year ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
README
# Skip Map
[](https://www.npmjs.com/package/skip-map) [](https://www.npmjs.com/package/skip-map) [](https://raw.githubusercontent.com/KyleRoss/express-skip-map/master/LICENSE)
Most developer tools built into browsers will automatically request a sourcemap file for `.js` and `.css` files that have been minified. In order prevent 404 errors showing in your express application constantly for missing `.map` files, use this middleware to skip HTTP requests for `.map` files. Don't use this module if you actually have sourcemap files for your minified files. Adding this to our applications was much easier than constantly reminding developers to turn off sourcemaps in their developer tools.
## Install
Using npm:
npm install skip-map --save
## Usage
Skip Map middleware **must** be called before any `static` middleware.
var express = require('express'),
skipMap = require('skip-map'),
app = express();
app.use(skipMap());
app.use(express.static('./public'));
app.listen(3000, function() {
console.log('Server is listening on port 3000');
});
### skipMap([callback])
Returns the skip map middleware function for Express. Takes an optional `callback` to define how requests for `.map` files should be handled. When a callback function is not provided, it will just end the request by calling `res.send('')`.
| Required? | Argument | Type | Description
| --------- | ----------- | ---------- | --------------------------------
| No | callback | Function | A callback function to define how to handle requests for `.map` files. Function is called with `req`, `res` and `next`.
Example:
// Without a callback function
app.use(skipMap());
// With a callback function
app.use(skipMap(function(req, res, next) {
console.log('Skipping request for a .map file');
res.send('');
}));
// Skip only in Development
app.use(skipMap(function(req, res, next) {
if(process.env.NODE_ENV === 'development') {
console.log('Skipping request for a .map file');
res.send('');
} else {
next(); // will try to load the .map file if exists
}
}));
---
## Issues
Found a bug? Have an enhancement? Create a new issue. I will try to get it fixed as soon as possible.
## Contributing
Want to contribute to the project? Fork and submit a pull request.
## License
Licensed under the MIT license. See LICENSE in the repository for more information.