File: setup.js

package info (click to toggle)
node-superagent 9.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,464 kB
  • sloc: javascript: 11,641; makefile: 77
file content (36 lines) | stat: -rw-r--r-- 690 bytes parent folder | download | duplicates (2)
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
35
36
require('should');
require('should-http');

const getPort = require('get-port');

let NODE;
let uri;

async function getSetup() {
  if (NODE && uri) {
    return { NODE, uri };
  }

  NODE = true;
  if (typeof window !== 'undefined') {
    NODE = false;
    uri = `//${window.location.host}`;
  } else {
    try {
      const port = await getPort();

      // check that another call to the function hasn't set the uri already
      if (!uri) {
        process.env.ZUUL_PORT = port;
        uri = `http://localhost:${process.env.ZUUL_PORT}`;
        require('./server');
      }
    } catch (err) {
      console.error(err);
    }
  }

  return { NODE, uri };
}

module.exports = getSetup;