Skip to content

Commit

Permalink
Fix cors errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chill389cc committed Sep 21, 2024
1 parent 58b08e6 commit 2762d02
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
28 changes: 28 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"dependencies": {
"@fastify/autoload": "^6.0.0",
"@fastify/cors": "^10.0.0",
"@fastify/type-provider-typebox": "^5.0.0",
"fastify": "^5.0.0",
"pino": "^9.4.0",
Expand Down
3 changes: 3 additions & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
sendBasicMessageResponse,
} from './util/errors'
import { logger, fastifyLogOpts } from './util/logger'
import cors from '@fastify/cors'

export default async function server (): Promise<FastifyInstance> {
const fastify = Fastify({
Expand All @@ -22,6 +23,8 @@ export default async function server (): Promise<FastifyInstance> {

fastify.setValidatorCompiler(TypeBoxValidatorCompiler)

fastify.register(cors)

// This loads all plugins defined in routes
// define your routes in one of these
fastify.register(AutoLoad, { // eslint-disable-line @typescript-eslint/no-floating-promises
Expand Down
8 changes: 6 additions & 2 deletions web/src/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import {useLoad, useTriggerLoad} from '../util/load';
import {useContext} from 'react';
import {ClientContext} from '../context/client-context';
import {add} from "../client/add";
import { AddResponse } from 'shared'

export const Main = memo(() => {
const client = useContext(ClientContext);
const client = useContext(ClientContext)

const quoteLoad = useLoad(async (abort) => {
const response = await fetch('https://bible-api.com/john 3:16', { signal: abort }).then((res) => res.json());
return response.text
}, []);

const [addLoadState, doAdd] = useTriggerLoad(async (abort) => {
const [addLoadState, doAdd] = useTriggerLoad<AddResponse>(async (abort) => {
if (!client) {
return
}
Expand All @@ -36,6 +37,9 @@ export const Main = memo(() => {
) : (
<button onClick={() => { doAdd() }}>Add</button>
)}
{addLoadState.value && (
<div>Hey, this is the value! {addLoadState.value?.result ?? 'undefined'}</div>
)}
</div>
);
});

0 comments on commit 2762d02

Please sign in to comment.