-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add simulationRoutes to store, display at base / route
- Loading branch information
Showing
5 changed files
with
189 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@simulacrum/foundation-simulator": minor:feat | ||
--- | ||
|
||
To improve transparency and flexibility, we now include a page at the root that lists all of the routes, and the ability to signal which response to return. |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type { SimulationRoute } from "./store/schema"; | ||
|
||
const responseSubmit = (routeId: string, response: number) => /* HTML */ `<form | ||
action="" | ||
method="post" | ||
> | ||
<input type="submit" name="${routeId}" value="${response}" /> | ||
</form>`; | ||
const routeToId = (route: SimulationRoute) => `${route.method}:${route.url}`; | ||
|
||
export const generateRoutesHTML = (routes: SimulationRoute[]) => { | ||
return /* HTML */ `<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Simulation Server Routes</title> | ||
<style> | ||
html { | ||
font-size: 16px; | ||
line-height: 1.5; | ||
background-color: #fff; | ||
color: #000; | ||
} | ||
body { | ||
margin: 0 auto; | ||
max-width: 720px; | ||
padding: 0 16px; | ||
font-family: sans-serif; | ||
} | ||
a { | ||
text-decoration: none; | ||
} | ||
.routes { | ||
display: grid; | ||
grid-template-columns: 20px auto auto auto; | ||
column-gap: 15px; | ||
} | ||
.route-actions { | ||
display: flex; | ||
gap: 5px; | ||
} | ||
li { | ||
margin-bottom: 8px; | ||
} | ||
/* Dark mode styles */ | ||
@media (prefers-color-scheme: dark) { | ||
html { | ||
background-color: #1e293b; | ||
color: #fff; | ||
} | ||
a { | ||
} | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<main class="my-12"> | ||
<h1>Simulation Routes</h1> | ||
<div class="routes"> | ||
${routes | ||
.map( | ||
(route) => | ||
`<span>${route.method.toUpperCase()}</span><a href=${ | ||
route.url | ||
}>${route.url}</a><span>returns: ${ | ||
route.defaultCode | ||
}, called ${ | ||
route.calls | ||
} times</span><div class="route-actions">${route.responses | ||
.map((response) => | ||
responseSubmit(routeToId(route), response) | ||
) | ||
.join("")}</div>` | ||
) | ||
.join("\n")} | ||
</div> | ||
</main> | ||
</body> | ||
</html>`; | ||
}; |
This file contains 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