source: trip-planner-front/node_modules/sockjs/lib/trans-htmlfile.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1// Generated by CoffeeScript 1.12.7
2(function() {
3 var HtmlFileReceiver, iframe_template, transport, utils,
4 extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
5 hasProp = {}.hasOwnProperty;
6
7 utils = require('./utils');
8
9 transport = require('./transport');
10
11 iframe_template = "<!doctype html>\n<html><head>\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n</head><body><h2>Don't panic!</h2>\n <script>\n document.domain = document.domain;\n var c = parent.{{ callback }};\n c.start();\n function p(d) {c.message(d);};\n window.onload = function() {c.stop();};\n </script>";
12
13 iframe_template += Array(1024 - iframe_template.length + 14).join(' ');
14
15 iframe_template += '\r\n\r\n';
16
17 HtmlFileReceiver = (function(superClass) {
18 extend(HtmlFileReceiver, superClass);
19
20 function HtmlFileReceiver() {
21 return HtmlFileReceiver.__super__.constructor.apply(this, arguments);
22 }
23
24 HtmlFileReceiver.prototype.protocol = "htmlfile";
25
26 HtmlFileReceiver.prototype.doSendFrame = function(payload) {
27 return HtmlFileReceiver.__super__.doSendFrame.call(this, '<script>\np(' + JSON.stringify(payload) + ');\n</script>\r\n');
28 };
29
30 return HtmlFileReceiver;
31
32 })(transport.ResponseReceiver);
33
34 exports.app = {
35 htmlfile: function(req, res) {
36 var callback;
37 if (!('c' in req.query || 'callback' in req.query)) {
38 throw {
39 status: 500,
40 message: '"callback" parameter required'
41 };
42 }
43 callback = 'c' in req.query ? req.query['c'] : req.query['callback'];
44 if (/[^a-zA-Z0-9-_.]/.test(callback)) {
45 throw {
46 status: 500,
47 message: 'invalid "callback" parameter'
48 };
49 }
50 res.setHeader('Content-Type', 'text/html; charset=UTF-8');
51 res.writeHead(200);
52 res.write(iframe_template.replace(/{{ callback }}/g, callback));
53 transport.register(req, this, new HtmlFileReceiver(req, res, this.options));
54 return true;
55 }
56 };
57
58}).call(this);
Note: See TracBrowser for help on using the repository browser.