Skip to content

Commit 41ebcfc

Browse files
committed
docs: add fake latency example
1 parent 9698f64 commit 41ebcfc

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

examples/server.latency.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
*
3+
* Install:
4+
* npm install browser-sync
5+
*
6+
* Run:
7+
* node <yourfile.js>
8+
*
9+
* This example will create a server & use the `app` directory as the root
10+
* - any requests begining with /json will have fake latency applied
11+
* - for 3 seconds
12+
*
13+
*/
14+
15+
"use strict";
16+
17+
var browserSync = require("browser-sync").create();
18+
19+
function fakeLatency (req, res, next) {
20+
if (req.url.match(/^\/json/)) {
21+
setTimeout(next, 3000);
22+
} else {
23+
next();
24+
}
25+
}
26+
27+
browserSync.init({
28+
files: ["app/css/*.css"],
29+
server: "app",
30+
middleware: [fakeLatency]
31+
});

0 commit comments

Comments
 (0)