Skip to content

Commit a9d9667

Browse files
committed
refactor: use tanstack way for returning json
1 parent c0134ea commit a9d9667

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

workbench/tanstack/src/routes/api/hook.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createFileRoute } from '@tanstack/react-router';
2+
import { json } from '@tanstack/react-start';
23
import { getHookByToken, resumeHook } from 'workflow/api';
34

45
export const Route = createFileRoute('/api/hook')({
@@ -14,8 +15,8 @@ export const Route = createFileRoute('/api/hook')({
1415
} catch (error) {
1516
console.log('error during getHookByToken', error);
1617
// TODO: `WorkflowAPIError` is not exported, so for now
17-
// we'll return 404 assuming it's the "invalid" token test case
18-
return Response.json(null, { status: 404 });
18+
// we'll return 400 assuming it's the "invalid" token test case
19+
return json(null, { status: 400 });
1920
}
2021

2122
await resumeHook(hook.token, {
@@ -24,7 +25,7 @@ export const Route = createFileRoute('/api/hook')({
2425
customData: hook.metadata?.customData,
2526
});
2627

27-
return Response.json(hook);
28+
return json(hook);
2829
},
2930
},
3031
},

workbench/tanstack/src/routes/api/signup.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createFileRoute } from '@tanstack/react-router';
2+
import { json } from '@tanstack/react-start';
23
import { start } from 'workflow/api';
34
import { handleUserSignup } from 'workflows/user-signup';
45

@@ -7,7 +8,7 @@ export const Route = createFileRoute('/api/signup')({
78
handlers: {
89
GET: async ({ request }) => {
910
const run = await start(handleUserSignup, ['test@example.com']);
10-
return Response.json(run);
11+
return json(run);
1112
},
1213
},
1314
},

workbench/tanstack/src/routes/api/trigger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createFileRoute } from '@tanstack/react-router';
2+
import { json } from '@tanstack/react-start';
23
import { allWorkflows } from '_workflows.js';
34
import { getRun, start } from 'workflow/api';
45
import { hydrateWorkflowArguments } from 'workflow/internal/serialization';
@@ -49,7 +50,7 @@ export const Route = createFileRoute('/api/trigger')({
4950
'Content-Type': 'application/octet-stream',
5051
},
5152
})
52-
: Response.json(returnValue);
53+
: json(returnValue);
5354
} catch (error) {
5455
if (error instanceof Error) {
5556
if (error.name === 'WorkflowRunNotCompletedError') {

workbench/tanstack/vite.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ const config = defineConfig({
1818
tanstackStart(),
1919
viteReact(),
2020
],
21-
build: {
22-
commonjsOptions: {
23-
transformMixedEsModules: true,
24-
},
25-
},
2621
});
2722

2823
export default config;

0 commit comments

Comments
 (0)