Skip to content

Conversation

@gormonn
Copy link

@gormonn gormonn commented Sep 22, 2020

add fetch options to pass headers

In some cases we need to pass api-key or something else.

For example:

app.get("/WebClient/*", 
  async (req, res, next) => {
    res.locals.fetchUrl = `http://someapi.ru/WebClient/${req.params[0]}?${encodeQuery(req.query)}`;
    res.locals.options = { headers: req.headers }
    next();
  },
  fileCacheMiddleware({ cacheDir, maxSize: 10 * 1024 * 1024 * 1024 * 1024 }),
  (req, res) => {
    res.set({
      "Content-Type": res.locals.contentType,
      "Content-Length": res.locals.contentLength
    });
    res.end(res.locals.buffer, "binary");
  }
);

add fetch options to pass headers
@julianrubisch
Copy link
Owner

Great, thanks!

I haven't looked in here for a while, and just to make sure we don't break anything - could you add a test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants