-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
34 lines (28 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
var read = require('fs').readFileSync
, jsdom = require('jsdom').jsdom
, join = require('path').join;
var scope = jsdom('<html><head></head><body></body></html>', {
agentOptions: { keepAlive: false }
}).defaultView;
//
// The library in Primus contains additional stability fixes which make it
// a lot more stable.
//
var lib = join(require.resolve('primus'), '../transformers/sockjs/library.js');
scope.WebSocket = require('ws');
//
// On Node 0.12 there are some issues with eval. It somehow doesn't correctly
// introduce the SockJS global. Using script tags fully resolves this issue.
//
var script = scope.document.createElement('script');
script.text = read(lib, 'utf-8');
scope.document.body.appendChild(script);
script = null;
//
// The href is `about:blank` by default. This doesn't work SockJS's same origin
// check as it cannot parse it and it start throwing errors when it attempts to
// find the host. So in order to fix this we need to force a HREF.
//
scope.location.href = 'http://localhost:8080/';
module.exports = scope.SockJS;