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

Unified 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, 12 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 side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/playback_middleware/lib/middleware.js
diff --git a/third_party/pkg/angular/playback_middleware/lib/middleware.js b/third_party/pkg/angular/playback_middleware/lib/middleware.js
new file mode 100644
index 0000000000000000000000000000000000000000..09382e1f35b9e3fc3760a753e8edb3bb1a791d4f
--- /dev/null
+++ b/third_party/pkg/angular/playback_middleware/lib/middleware.js
@@ -0,0 +1,50 @@
+
+var url = require('url');
+var playback = require('./playback.js');
+
+/**
+ * Returns connect middleware that will record and playback for Angular.dart's
+ * HTTP playback service.
+ * @param opts
+ * path is the path where the record / playback endpoint is served
+ * playbackImpl is the playback module, used for mocking
+ * @returns {Function}
+ */
+function endpoint(opts) {
+ opts = opts || {};
+ opts.path = opts.path || '/record';
+ opts.playbackImpl = opts.playbackImpl || playback.playback();
+
+
+ return function playbackEndpoint(req, res, next) {
+ if (url.parse(req.url).path != opts.path) {
+ next();
+ return;
+ }
+
+ if (req.method == 'POST') {
+ var body = '';
+ req.on('data', function(data) {
+ body += data;
+ });
+ req.on('end', function() {
+ var parsedBody = JSON.parse(body);
+
+ opts.playbackImpl.record(parsedBody.key, parsedBody.data);
+ res.writeHead(200);
+ res.end();
+ });
+ } else if (req.method == 'GET') {
+ var data = opts.playbackImpl.playback();
+ res.writeHead(200, {
+ 'Content-Type': 'application/dart',
+ 'Content-Length': Buffer.byteLength(data)
+ });
+ res.end(data);
+ }
+ }
+}
+
+module.exports = {
+ endpoint: endpoint
+};

Powered by Google App Engine
This is Rietveld 408576698