Giter VIP home page Giter VIP logo

express-skip-map's Introduction

Skip Map

npm npm GitHub 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.

express-skip-map's People

Contributors

kyleross avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.