forked from Shorthand/software-engineer-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
28 lines (27 loc) · 870 Bytes
/
vite.config.ts
File metadata and controls
28 lines (27 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
// Custom middleware to proxy arbitrary URLs server-side, bypassing CORS
// Usage: GET /api/proxy?url=https://example.com
{
name: "cors-proxy",
configureServer(server) {
server.middlewares.use("/api/proxy", async (req, res) => {
const target = new URL(req.url!, `http://${req.headers.host}`).searchParams.get("url");
if (!target) {
res.statusCode = 400;
res.end("Missing url parameter");
return;
}
const response = await fetch(target);
const html = await response.text();
res.setHeader("Content-Type", "text/html");
res.end(html);
});
},
},
],
});