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

Fix MSW build #46

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions frontend/app/component/MockTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from "react";

export function MockTest() {
const [message, setMessage] = React.useState("...");

React.useEffect(() => {
const action = async () => {
const response = await fetch("/v1/ping", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ ping: "ping" }),
});

const data = (await response.json()) as object;
setMessage(`Response: ${JSON.stringify(data)}`);
};

action().catch((err: unknown) => {
setMessage(`Error: ${err instanceof Error ? err.message : String(err)}`);
});
}, []);
return (
<div>
<h4>Testing mockserver</h4>
{message && <p>{message}</p>}
</div>
);
}
3 changes: 3 additions & 0 deletions frontend/app/module/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MockTest } from "app/component/MockTest";
import { Link } from "react-router-dom";

export function HomePage() {
Expand All @@ -11,6 +12,8 @@ export function HomePage() {
<Link to={`/input`}>Input module</Link>
</li>
</ul>

{process.env.MSW && <MockTest />}
</div>
);
}
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<title>TBD</title>
<link rel="icon" href="favicon.svg" />
<link rel="icon" href="/favicon.svg" />
<meta viewport="width=device-width, initial-scale=1" />
</head>
<body>
Expand Down
5 changes: 3 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "API_MODE=mock vite",
"dev:server": "API_MODE=local vite",
"build": "tsc && vite build",
"build:msw": "API_MODE=msw vite build && cp mockServiceWorker.js dist/",
"build:msw": "API_MODE=mock vite build && cp mockServiceWorker.js dist/",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"test": "vitest ",
Expand All @@ -19,7 +19,8 @@
"ladle": "ladle serve",
"start:msw": "API_MODE=msw vite",
"gen:icons": "node scripts/gen_icons.js",
"gen:openapi": "vite-node ./scripts/gen_openapi_types.ts"
"gen:openapi": "vite-node ./scripts/gen_openapi_types.ts",
"serve": "npm run build:msw && npx serve dist"
},
"dependencies": {
"react": "^18.2.0",
Expand Down
7 changes: 6 additions & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ export default defineConfig(() => ({
outDir: path.resolve(__dirname, "dist"),
emptyOutDir: true,
sourcemap: true,
// minify: false, // uncomment for debugging
minify: false,
rollupOptions: {
input: {
app: "index.html",
},
},
},
define: {
"process.env.MSW": apiMode === "mock",
Expand Down