source: trip-planner-front/node_modules/sockjs/lib/trans-eventsource.js@ 8d391a1

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

initial commit

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[6a3a178]1// Generated by CoffeeScript 1.12.7
2(function() {
3 var EventSourceReceiver, 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 EventSourceReceiver = (function(superClass) {
12 extend(EventSourceReceiver, superClass);
13
14 function EventSourceReceiver() {
15 return EventSourceReceiver.__super__.constructor.apply(this, arguments);
16 }
17
18 EventSourceReceiver.prototype.protocol = "eventsource";
19
20 EventSourceReceiver.prototype.doSendFrame = function(payload) {
21 var data;
22 data = ['data: ', utils.escape_selected(payload, '\r\n\x00'), '\r\n\r\n'];
23 return EventSourceReceiver.__super__.doSendFrame.call(this, data.join(''));
24 };
25
26 return EventSourceReceiver;
27
28 })(transport.ResponseReceiver);
29
30 exports.app = {
31 eventsource: function(req, res) {
32 var headers, origin;
33 if (!req.headers['origin'] || req.headers['origin'] === 'null') {
34 origin = '*';
35 } else {
36 origin = req.headers['origin'];
37 res.setHeader('Access-Control-Allow-Credentials', 'true');
38 }
39 res.setHeader('Content-Type', 'text/event-stream');
40 res.setHeader('Access-Control-Allow-Origin', origin);
41 res.setHeader('Vary', 'Origin');
42 headers = req.headers['access-control-request-headers'];
43 if (headers) {
44 res.setHeader('Access-Control-Allow-Headers', headers);
45 }
46 res.writeHead(200);
47 res.write('\r\n');
48 transport.register(req, this, new EventSourceReceiver(req, res, this.options));
49 return true;
50 }
51 };
52
53}).call(this);
Note: See TracBrowser for help on using the repository browser.