Exemple #1
0
    (resource, handler, next) => {
      Insync.eachSeries(STATUS_CODES, (code, cb) => {
        const c = parseInt(code, 10);

        if (c < 400 && c !== 200) {
          return cb();
        }

        const options = {
          httpMethod: method,
          resourceId: resource.id,
          restApiId: this._id,
          statusCode: code,
          responseTemplates: { 'application/json': '' }
        };

        if (c >= 400) {
          // TODO: Map the stringified error back to an object
          // See https://aws.amazon.com/blogs/compute/amazon-api-gateway-mapping-improvements/
          options.selectionPattern = `.*"statusCode\\":${c}.*`;
        }

        this._gateway.putIntegrationResponse(options, cb);
      }, (err) => {
        next(err, resource, handler);
      });
    },
Exemple #2
0
    (resources, next) => {
      // Assuming the / resource is always at index 0
      let previous = resources.items[0];
      let path = '';

      Insync.eachSeries(pathParts, (part, cb) => {
        path += `/${part}`;
        const existing = resources.items.filter((resource) => {
          return resource.path === path;
        }).pop();

        if (existing) {
          previous = existing;
          return cb();
        }

        this._gateway.createResource({
          parentId: previous.id,
          pathPart: part,
          restApiId: this._id
        }, (err, resource) => {
          previous = resource;
          cb(err);
        });
      }, (err) => {
        next(err, previous);
      });
    },
Exemple #3
0
 (resource, handler, next) => {
   Insync.eachSeries(STATUS_CODES, (code, cb) => {
     // TODO: Look into supporting multiple HTTP status codes better
     // TODO: Optionally let users specify the codes they actually use
     this._gateway.putMethodResponse({
       httpMethod: method,
       resourceId: resource.id,
       restApiId: this._id,
       statusCode: code,
       responseModels: { 'application/json': 'Empty' }
     }, cb);
   }, (err) => {
     next(err, resource, handler);
   });
 },