How to use koa-better-http-proxy - 1 common examples

To help you get started, we’ve selected a few koa-better-http-proxy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Shopify / quilt / packages / koa-shopify-graphql-proxy / src / shopify-graphql-proxy.ts View on Github external
const shop = 'shop' in proxyOptions ? proxyOptions.shop : session.shop;
    const accessToken =
      'password' in proxyOptions ? proxyOptions.password : session.accessToken;
    const version = proxyOptions.version;

    if (ctx.path !== PROXY_BASE_PATH || ctx.method !== 'POST') {
      await next();
      return;
    }

    if (accessToken == null || shop == null) {
      ctx.throw(403, 'Unauthorized');
      return;
    }

    await proxy(shop, {
      https: true,
      parseReqBody: false,
      // Setting request header here, not response. That's why we don't use ctx.set()
      // proxy middleware will grab this request header
      headers: {
        'Content-Type': 'application/json',
        'X-Shopify-Access-Token': accessToken,
      },
      proxyReqPathResolver() {
        return `${GRAPHQL_PATH_PREFIX}/${version}/graphql.json`;
      },
    })(
      ctx,

      /*
        We want this middleware to terminate, not fall through to the next in the chain,

koa-better-http-proxy

http proxy middleware for koa

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis

Popular koa-better-http-proxy functions