Skip to content

Commit 9289f59

Browse files
committed
fix: redirection after sync
1 parent e81ca10 commit 9289f59

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ bun run dev
99
Then, in the Drama queen .env set
1010

1111
```env
12-
VITE_QUEEN_API_URL=http://localhost:3000
12+
VITE_QUEEN_API_URL=http://localhost:5000
1313
```
1414

1515
Then you can request a synchronization (http://localhost:5001/queen/synchronize) to get fake data from this API

server/src/index.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Hono } from 'hono'
2+
import { serveStatic } from 'hono/bun'
23
import { cors } from 'hono/cors'
34

45
import Roundabout from '../mocks/roundabout.json'
@@ -16,8 +17,8 @@ const defaultStateData = {
1617

1718
// Fake the database with an in memory map
1819
const interrogations = new Map(
19-
Array.from({ length: 5 }).map((_, k) => {
20-
const id = `i${k}`
20+
Array.from({ length: 10 }).map((_, k) => {
21+
const id = `su${k}`
2122
return [
2223
id,
2324
{
@@ -39,7 +40,7 @@ const interrogations = new Map(
3940
}),
4041
)
4142

42-
app.use('/api/*', cors())
43+
app.use('/*', cors())
4344

4445
app.use(async (_, next) => {
4546
await new Promise((resolve) => setTimeout(resolve, waitTime))
@@ -50,14 +51,11 @@ app.get('/api/healthcheck', (c) => {
5051
return c.json({})
5152
})
5253

54+
/**
55+
* Interrogations
56+
*/
5357
app.get('/api/interrogations/state-data', (c) => {
54-
return c.json([{ id: 'i2' }, { id: 'i3' }])
55-
})
56-
57-
app.put('/api/interrogations/:id', async (c) => {
58-
const data = await c.req.json()
59-
interrogations.set(c.req.param('id'), data)
60-
return c.json({})
58+
return c.json([{ id: 'su2' }, { id: 'su3' }])
6159
})
6260

6361
app.post('/api/interrogations/:id/synchronize', async (c) => {
@@ -72,6 +70,19 @@ app.post('/api/interrogations/:id/synchronize', async (c) => {
7270
})
7371
})
7472

73+
app.get('/api/interrogations/:id', (c) => {
74+
return c.json(interrogations.get(c.req.param('id')))
75+
})
76+
77+
app.put('/api/interrogations/:id', async (c) => {
78+
const data = await c.req.json()
79+
interrogations.set(c.req.param('id'), data)
80+
return c.json({})
81+
})
82+
83+
/**
84+
* Campaigns
85+
*/
7586
app.get('/api/campaigns', (c) => {
7687
return c.json([
7788
{
@@ -84,10 +95,6 @@ app.get('/api/campaigns', (c) => {
8495
])
8596
})
8697

87-
app.get('/api/questionnaire/:id', (c) => {
88-
return c.json({ value: Roundabout })
89-
})
90-
9198
app.get('/api/campaign/:id/interrogations', (c) => {
9299
return c.json(
93100
Array.from(interrogations.values()).map((interrogation) => ({
@@ -97,13 +104,14 @@ app.get('/api/campaign/:id/interrogations', (c) => {
97104
)
98105
})
99106

100-
app.get('/api/interrogations/:id', (c) => {
101-
return c.json(interrogations.get(c.req.param('id')))
107+
app.get('/api/questionnaire/:id', (c) => {
108+
return c.json({ value: Roundabout })
102109
})
103110

104-
const port = 5000
111+
// Serve static files for all non-API routes
112+
app.use('/*', serveStatic({ root: '../dist' }))
105113

106-
console.log(`== Starting fake Queen API Server on http://localhost:${port}`)
114+
const port = 5000
107115

108116
export default {
109117
port,

src/routes/pages/synchronize/SynchronizeData.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function SynchronizeData() {
2323
(data) => (data.action === 'redirect' ? [data] : null),
2424
ctx,
2525
() => {
26-
//window.location.href = window.location.origin
26+
window.location.href = window.location.origin
2727
},
2828
)
2929
}, [])

0 commit comments

Comments
 (0)