}).then(function() {
      // Create validator
      var validatorCreated = validator({
        folder:         path.join(__dirname, 'schemas'),
        baseUrl:        'http://localhost:4321/'
      });

      // Create server for api
      return validatorCreated.then(function(validator) {
        // Create router
        var router = api.router({
          validator:      validator,
          authBaseUrl:    'http://localhost:61243'
        });

        // Create application
        var app = express();

        // Use router
        app.use(router);

        return new Promise(function(accept, reject) {
          var server = app.listen(61515);
          server.once('listening', function() {
            accept(server)
          });
          server.once('error', reject);
          _apiServer = server;
        });
      });
    });
Ejemplo n.º 2
0
  test("Context properties can be required", async () => {
    // Create test api
    var api = new subject({
      title:        "Test Api",
      description:  "Another test api",
      context:      ['prop1', 'prop2']
    });

    var value = slugid.v4();
    let validate = await validator({
      folder:         path.join(__dirname, 'schemas'),
      baseUrl:        'http://localhost:4321/'
    });
    try {
      api.router({
        validator:  validate,
        context: {
          prop1: "value1"
        }
      });
    } catch (err) {
      return; // expected error
    }
    assert(false, "Expected an error!");
  });
    }).then(function() {
      // Create server for api
      return validator({
        folder:         path.join(__dirname, 'schemas'),
        baseUrl:        'http://localhost:4321/'
      }).then(function(validator) {
        influx = new stats.Influx({
          connectionString:   cfg.get('influxdb:connectionString')
        });

        // Create router
        var router = api.router({
          validator:      validator,
          authBaseUrl:    'http://localhost:23243',
          component:      'ResponseTimerTest',
          drain:           influx
        });

        // Create application
        var app = express();

        // Use router
        app.use(router);

        return new Promise(function(accept, reject) {
          var server = app.listen(23525);
          server.once('listening', function() {
            accept(server)
          });
          server.once('error', reject);
          _apiServer = server;
        });
      });
    });
Ejemplo n.º 4
0
  test("Provides context", async () => {
    // Create test api
    var api = new subject({
      title:        "Test Api",
      description:  "Another test api"
    });

    api.declare({
      method:   'get',
      route:    '/context/',
      name:     'getContext',
      title:    "Test End-Point",
      description:  "Place we can call to test something",
    }, function(req, res) {
      res.status(200).json({myProp: this.myProp});
    });

    var value = slugid.v4();
    let validate = await validator({
      folder:         path.join(__dirname, 'schemas'),
      baseUrl:        'http://localhost:4321/'
    });
    var router = api.router({
      validator:  validate,
      context: {
        myProp: value
      }
    });

    var app = makeApp({
      port:       60872,
      env:        'development',
      forceSSL:   false,
      trustProxy: false,
    });

    app.use('/v1', router);

    let server = await app.createServer();

    await request
      .get('http://localhost:60872/v1/context')
      .end()
      .then(function(res) {
        assert(res.body.myProp === value);
      }).then(function () {
        return server.terminate();
      }, function(err) {
        return server.terminate().then(function() {
          throw err;
        });
      });
  });
Ejemplo n.º 5
0
module.exports = async ({authBaseUrl, rootAccessToken}) => {
  // Create application
  let serverApp = app({
    port:           PORT,
    env:            'development',
    forceSSL:       false,
    trustProxy:     false,
  });

  // Create router for the API
  let router = myapi.router({
    authBaseUrl,
    validator: await validator({
      prefix: 'auth/v1',
    }),
  });

  // Mount router
  serverApp.use('/v1', router);

  // Create server
  let server = await serverApp.createServer();
  let baseUrl = 'http://localhost:' + server.address().port + '/v1';

  let reference = myapi.reference({baseUrl});
  let MyClient = taskcluster.createClient(reference);
  let myClient = new MyClient({
    baseUrl,
    credentials: {
      clientId: 'root',
      accessToken: rootAccessToken,
    },
  });

  return {
    server,
    reference,
    baseUrl,
    Client: MyClient,
    client: myClient,
  };
};
Ejemplo n.º 6
0
  test("Context properties can provided", async () => {
    // Create test api
    var api = new subject({
      title:        "Test Api",
      description:  "Another test api",
      context:      ['prop1', 'prop2']
    });

    var value = slugid.v4();
    let validate = await validator({
      folder:         path.join(__dirname, 'schemas'),
      baseUrl:        'http://localhost:4321/'
    });
    api.router({
      validator:  validate,
      context: {
        prop1: "value1",
        prop2: "value2"
      }
    });
  });
Ejemplo n.º 7
0
 setup: ({cfg}) => validator({
   prefix: 'index/v1/',
   aws:    cfg.aws,
 }),