aboutsummaryrefslogtreecommitdiff
path: root/node_modules/express-minify/examples/no_minify.js
blob: b8dfc309f06429b4b62b6ea75de8dcc12769195e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var minify = require('express-minify');
var express = require('express');
var app = express();

app.use(function(req, res, next)
{
    // for all *.min.css or *.min.js, do not minify it
    if (/\.min\.(css|js)$/.test(req.url)) {
        res._no_minify = true;
    }
    next();
});

app.use(minify());

app.get('/server_time_min.jsonp', function(req, res)
{
    var obj = {
        'ok': true,
        'data': {
            'timestamp': new Date().getTime()
        }
    };

    // minify this response, but do not cache it
    res._no_cache = true;
    res.setHeader('Content-Type', 'application/javascript');
    res.send("callback(" + JSON.stringify(obj, null, 4) + ");");
});

app.get('/server_time.jsonp', function(req, res)
{
    var obj = {
        'ok': true,
        'data': {
            'timestamp': new Date().getTime()
        }
    };

    // do not minify this response
    res._no_minify = true;
    res.setHeader('Content-Type', 'application/javascript');
    res.send("callback(" + JSON.stringify(obj, null, 4) + ");");
});

app.use(express.static(__dirname + '/static'));

app.listen(8080);