Skip to content

Commit

Permalink
sub routing bits
Browse files Browse the repository at this point in the history
  • Loading branch information
karimsa committed Mar 6, 2023
1 parent 8d95915 commit e91db2e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (server *Server) Run() error {

// TODO: Move the compiler routes to a separate file/into compiler
// Apps
server.router.GET("/api/app-resources/:id/base.html", func(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
server.router.GET("/api/app-resources/:id/base/*filepath", func(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
id := params.ByName("id")
res.Header().Set("Content-Type", "text/html; charset=utf-8")

Expand Down
10 changes: 9 additions & 1 deletion backend/robin.servers.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"devServers": {
"cli": "go run github.com/mitranim/gow -e 'go,tsx,html' run ./cmd/cli start"
"cli": {
"healthChecks": [
{
"type": "tcp",
"port": 9010
}
],
"command": "go run github.com/mitranim/gow -e 'go,tsx,html' run ./cmd/cli start"
}
}
}
9 changes: 8 additions & 1 deletion frontend/components/AppWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ function AppWindowContent({ id, setTitle }: AppWindowProps) {

const iframeRef = React.useRef<HTMLIFrameElement | null>(null);
const [error, setError] = React.useState<string | null>(null);
const subRoute = React.useMemo(
() =>
router.isReady
? router.asPath.substring('/app/'.length + id.length)
: null,
[router.isReady, router.asPath, id],
);

React.useEffect(() => {
const onMessage = (message: MessageEvent) => {
Expand Down Expand Up @@ -143,7 +150,7 @@ function AppWindowContent({ id, setTitle }: AppWindowProps) {

<iframe
ref={iframeRef}
src={`http://localhost:9010/api/app-resources/${id}/base.html`}
src={`http://localhost:9010/api/app-resources/${id}/base${subRoute}`}
style={{ border: '0', flexGrow: 1, width: '100%', height: '100%' }}
/>
</>
Expand Down
1 change: 1 addition & 0 deletions frontend/pages/app/[id]/[...subRoute].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './index';

0 comments on commit e91db2e

Please sign in to comment.