Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenient passthru method #31

Closed
jcubic opened this issue Aug 22, 2023 · 1 comment
Closed

Add convenient passthru method #31

jcubic opened this issue Aug 22, 2023 · 1 comment
Labels
feature New feature or request

Comments

@jcubic
Copy link
Owner

jcubic commented Aug 22, 2023

There is a need for the API that will just use the same request but to the server. This similar to #22 that is not enough.

Consider code of syntax highlighting:

app.get('*', async function(req, res) {
  const url = new URL(req.url);
  const extension = path.extname(url.pathname).substring(1);
  const language = language_map[extension];
  const accept = req.headers.get('Accept');
  if (language && Prism.languages[language] && accept.match(/text\/html/)) {
      const code = await fetch(req.url).then(res => res.text());
      const grammar = Prism.languages[language];
      const tokens = Prism.tokenize(code, grammar);
      const output = Prism.Token.stringify(tokens, language);
      res.html(`${style}\n<pre><code class="language-${language}">${output}</code></pre>`);
  } else {
      const fetch_res = await fetch(req.url);
      res._resolve(fetch_res);
  }
});

from gh-pages branch: sw.js.

So there is a need to use hidden _resolve method that accept response object.

@jcubic jcubic added the feature New feature or request label Aug 22, 2023
@jcubic
Copy link
Owner Author

jcubic commented Aug 22, 2023

It seems that there is already:

res.fetch(req.url);

But it would be better to use a request object that have all the headers not only URL.

So the fetch need to be overloaded.

@jcubic jcubic closed this as completed Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant