Skip to content

Commit 1b7d111

Browse files
author
Guilherme Oenning
committed
better example and adding ignore
1 parent 8f9ffff commit 1b7d111

File tree

9 files changed

+101
-31
lines changed

9 files changed

+101
-31
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
logs
2+
*.log
3+
npm-debug.log*
4+
pids
5+
*.pid
6+
*.seed
7+
lib-cov
8+
coverage
9+
.nyc_output
10+
.grunt
11+
.lock-wscript
12+
build/Release
13+
node_modules
14+
jspm_packages
15+
.npm
16+
.node_repl_history

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "ui"]
22
path = ui
3-
url = git@github.com:MiniProfiler/ui.git
3+
url = https://github.com/MiniProfiler/ui.git

connect_test.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/express/server.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var miniprofiler = require('../../miniprofiler.js');
2+
var pg = require('pg');
3+
var miniprofilerPG = function(pg) {
4+
return function (req, res, next) {
5+
if (req.miniprofiler.enabled) {
6+
var pgQuery = pg.Client.prototype.query
7+
pg.Client.prototype.query = function(config, values, callback) {
8+
req.miniprofiler.timeQuery('sql', 'SELECT $1::int AS number', pgQuery.bind(this), config, values, callback);
9+
pg.Client.prototype.query = pgQuery
10+
}
11+
}
12+
next()
13+
}
14+
}
15+
16+
var express = require('express');
17+
var connString = "postgres://postgres:postgres@localhost/async_demo";
18+
19+
// Defaults to 'left'. Uncomment this to move to right. Also supports 'bottomLeft', 'bottomRight'.
20+
/*
21+
miniprofiler.configure({
22+
popupRenderPosition: 'right'
23+
});
24+
*/
25+
26+
var app = express();
27+
app.use(miniprofiler.profile());
28+
app.use(miniprofilerPG(pg));
29+
30+
app.set('view engine', 'pug');
31+
app.set('views', './examples/views')
32+
33+
app.get('/', function(req, res) {
34+
pg.connect(connString, function(err, client, done) {
35+
client.query('SELECT $1::int AS number', ['1'], function(err, result) {
36+
done();
37+
res.render('home');
38+
});
39+
});
40+
});
41+
42+
app.get('/multi-query', function(req, res) {
43+
req.miniprofiler.step('Step 1', function() {
44+
req.miniprofiler.step('Step 2', function() {
45+
req.miniprofiler.timeQuery('sql', 'SELECT * FROM TEST', function() {
46+
req.miniprofiler.timeQuery('sql', 'SELECT * FROM TEST', function() {
47+
res.render('multi-query');
48+
});
49+
});
50+
});
51+
});
52+
});
53+
54+
app.listen(8080);

examples/views/home.pug

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extends ./layout.pug
2+
3+
block content
4+
h1 Home Page

examples/views/layout.pug

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
doctype html
2+
html
3+
head
4+
title MiniProfiler Node.js Example
5+
body
6+
block content
7+
| !{miniprofiler.include()}

examples/views/multi-query.pug

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
extends ./layout.pug
2+
3+
block content
4+
h1 Multi Query Demo Page

miniprofiler.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ var version = '';
5959

6060
var contentTypes = {
6161
css: 'text/css',
62-
js: 'text/javascript'
62+
js: 'text/javascript',
63+
tmpl: 'text/html'
6364
};
6465
function static(reqPath, res) {
6566
fs.readFile(path.join(includesDir, reqPath), function(err, data) {
@@ -137,6 +138,7 @@ function middleware(f) {
137138
res.send(404);
138139
return;
139140
}
141+
140142
var sp = req.path.split('/');
141143
var reqPath = sp[sp.length - 1];
142144
if(reqPath == 'results')
@@ -146,8 +148,13 @@ function middleware(f) {
146148
return;
147149
}
148150
var id = startProfiling(req, enabled);
151+
152+
res.locals.miniprofiler = enabled ? req.miniprofiler : {
153+
include: function() { return '' }
154+
}
155+
149156
if (enabled) {
150-
res.on('header', function() {
157+
res.on('finish', function() {
151158
stopProfiling(req);
152159
});
153160
res.setHeader("X-MiniProfiler-Ids", '["' + id + '"]');

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
"url": "https://github.com/MiniProfiler/node.git"
1212
},
1313
"author": "",
14-
"license": "Apache 2.0",
14+
"license": "Apache-2.0",
1515
"readmeFilename": "README.md",
16-
"gitHead": "2a757088d0ee39fb7ecd68edaf80a4527b077848"
16+
"devDependencies": {
17+
"express": "^4.13.4",
18+
"pg": "^4.5.5",
19+
"pug": "^2.0.0-alpha6"
20+
}
1721
}

0 commit comments

Comments
 (0)