Skip to content

Conversation

@gabrielcsapo
Copy link

fixes #287

This is the demo code I ran to get some output from my experiment

<!DOCTYPE html>
<head>
  <meta charset="UTF-8">
  <title>Pretenderjs</title>
</head>
<body>
  <script src="./dist/pretender.bundle.js"></script>
  <script>
    (async function() {
      const server = new Pretender(function() {
        this.get('/hello-world', request => [200, {}, "hello world!"]);
      });

      server.unhandledRequest = function(verb, path, request) {
        console.log(verb, path, request);
      }
      
      await fetch('/hello-world');
    }())
  </script>
</body>
</html>

Screen Shot 2022-06-09 at 11 38 29 PM

Screen Shot 2022-06-09 at 11 38 30 PM

unhandled requests work as well!

<!DOCTYPE html>
<head>
  <meta charset="UTF-8">
  <title>Pretenderjs</title>
</head>
<body>
  <script src="./dist/pretender.bundle.js"></script>
  <script>
    (async function() {
      const server = new Pretender(function() {
        this.get('/hello-world', request => [200, {}, "hello world!"]);
      });

      server.unhandledRequest = function(verb, path, request) {
        console.log('unhandledRequest', verb, path, request);
      }
      
      await fetch('/hello-world');
      await fetch('/hello');
    }())
  </script>
</body>
</html>

Screen Shot 2022-06-09 at 11 45 40 PM

@gabrielcsapo gabrielcsapo marked this pull request as ready for review November 15, 2022 19:50
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.

Intercept XMLHttpRequest through a Service Worker

1 participant