Files
85a2a029bc Fix/msw-issue-68521 (#83482)
### Fix: [68521](https://github.com/vercel/next.js/issues/68521)
Updating outdated with-msw example
The
[with-msw](https://github.com/vercel/next.js/tree/canary/examples/with-msw)
is outdated and doesn't work with the latest msw version.

### What?
The
[with-msw](https://github.com/vercel/next.js/tree/canary/examples/with-msw)
example is outdated and does not work with the latest msw version.

### Why?
- msw now uses http instead of rest and the outdated implementation does
not work with the latest version anymore.
- the client-side worker is now imported through msw/browser.

### How?
- replaced all usage of rest with http to align with MSW's new API.
- updated the worker import to use msw/browser as per the new structure.

### Media

https://github.com/user-attachments/assets/ab9ebb49-28b2-4095-aeea-dcd301093c9f

---------

Co-authored-by: Joseph <[email protected]>
2025-09-08 09:11:34 +02:00

26 lines
958 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { http, HttpResponse } from "msw";
import { Book, Review } from "./types";
export const handlers = [
http.get("https://my.backend/book", () => {
const book: Book = {
title: "Lord of the Rings",
imageUrl: "/book-cover.jpg",
description:
"The Lord of the Rings is an epic high-fantasy novel written by English author and scholar J. R. R. Tolkien.",
};
return HttpResponse.json(book);
}),
http.get("/reviews", () => {
const reviews: Review[] = [
{
id: "60333292-7ca1-4361-bf38-b6b43b90cb16",
author: "John Maverick",
text: "Lord of The Rings, is with no absolute hesitation, my most favored and adored book by‑far. The trilogy is wonderful‑ and I really consider this a legendary fantasy series. It will always keep you at the edge of your seat‑ and the characters you will grow and fall in love with!",
},
];
return HttpResponse.json(reviews);
}),
];