This script is based on this StackOverflow answer, with some modifications to fix its issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { rest } from "msw"; | |
// https://vitejs.dev/guide/features.html#glob-import | |
const imports = import.meta.glob("./api/**/*.ts", { eager: true }); | |
export const handlers = Object.entries(imports).reduce( | |
(allHandlers, [path, handlers]) => { | |
// map "./path/[to]/handlers.js" -> "/api/path/:to/handlers" | |
const apiPath = | |
"/" + |
OlderNewer