File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ 1 . future make sure build a simple functionality which will use things like async, await and to understand . if see how it will work without this then how this keywords will help.
2+ 2 . Even for the cors do this kind of thing.
Original file line number Diff line number Diff line change 1- function Header ( ) {
2- return (
3- < header >
4- < h1 > Personal Vault</ h1 >
5- </ header >
6- ) ;
7- }
1+ import { useState , useEffect } from 'react' ;
2+
3+ function App ( ) {
4+ const [ notes , setNotes ] = useState ( [ ] ) ;
5+
6+ useEffect ( ( ) => {
7+ fetch ( 'http://localhost:8000/notes?user_id=1' )
8+ . then ( res => res . json ( ) )
9+ . then ( data => setNotes ( data ) ) ;
10+ } , [ ] ) ;
11+
12+ return (
13+ < div style = { { padding : "1rem" } } >
14+ < h1 > My Notes</ h1 >
15+ { notes . map ( note => (
16+ < p key = { note . id } > { note . title } </ p >
17+ ) ) }
18+ </ div >
19+ ) ;
20+ }
821
9- function App ( ) {
10- return (
11- < div >
12- < Header />
13- < p > Hello from React</ p >
14- </ div >
15- ) ;
16- }
1722export default App ;
Original file line number Diff line number Diff line change 77DATABASE_URL = os .getenv ("DATABASE_URL" , "" )
88SECRET_KEY = os .getenv ("SECRET_KEY" , "" )
99VAULT_ENCRYPTION_KEY = os .getenv ("VAULT_ENCRYPTION_KEY" , "" )
10+ CORS_ORIGINS = os .getenv ("CORS_ORIGINS" , "http://localhost:5173" ).split ("," )
Original file line number Diff line number Diff line change 11from fastapi import FastAPI
22from fastapi .staticfiles import StaticFiles
33from fastapi .responses import FileResponse
4- from app .config import APP_ENV
4+ from fastapi .middleware .cors import CORSMiddleware
5+ from app .config import APP_ENV , CORS_ORIGINS
56from app .routers import health
67from app .routers import users
78from app .routers import notes
1415 version = "0.1.0" ,
1516)
1617
18+ app .add_middleware (
19+ CORSMiddleware ,
20+ allow_origins = CORS_ORIGINS ,
21+ allow_credentials = True ,
22+ allow_methods = ["*" ],
23+ allow_headers = ["*" ],
24+ )
25+
1726app .include_router (health .router )
1827app .include_router (users .router )
1928app .include_router (notes .router )
Load diff This file was deleted.
Load diff This file was deleted.
Load diff This file was deleted.
You can’t perform that action at this time.
0 commit comments