Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: third_party/pkg/angular/playback_middleware/lib/middleware.js

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1
2 var url = require('url');
3 var playback = require('./playback.js');
4
5 /**
6 * Returns connect middleware that will record and playback for Angular.dart's
7 * HTTP playback service.
8 * @param opts
9 * path is the path where the record / playback endpoint is served
10 * playbackImpl is the playback module, used for mocking
11 * @returns {Function}
12 */
13 function endpoint(opts) {
14 opts = opts || {};
15 opts.path = opts.path || '/record';
16 opts.playbackImpl = opts.playbackImpl || playback.playback();
17
18
19 return function playbackEndpoint(req, res, next) {
20 if (url.parse(req.url).path != opts.path) {
21 next();
22 return;
23 }
24
25 if (req.method == 'POST') {
26 var body = '';
27 req.on('data', function(data) {
28 body += data;
29 });
30 req.on('end', function() {
31 var parsedBody = JSON.parse(body);
32
33 opts.playbackImpl.record(parsedBody.key, parsedBody.data);
34 res.writeHead(200);
35 res.end();
36 });
37 } else if (req.method == 'GET') {
38 var data = opts.playbackImpl.playback();
39 res.writeHead(200, {
40 'Content-Type': 'application/dart',
41 'Content-Length': Buffer.byteLength(data)
42 });
43 res.end(data);
44 }
45 }
46 }
47
48 module.exports = {
49 endpoint: endpoint
50 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698