File tree 4 files changed +37
-40
lines changed
4 files changed +37
-40
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ edition = "2021"
6
6
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
7
8
8
[dependencies ]
9
- salvo = { version = " *" , features = [" oapi" ] }
9
+ salvo = { version = " *" , features = [" oapi" , " cors " ] }
10
10
tokio = { version = " 1" , features = [" macros" ] }
11
11
tracing = " 0.1.40"
12
12
tracing-subscriber = " 0.3"
Original file line number Diff line number Diff line change
1
+ use salvo:: cors:: Cors ;
2
+ use salvo:: hyper:: Method ;
1
3
use salvo:: oapi:: extract:: * ;
2
4
use salvo:: prelude:: * ;
3
5
@@ -14,9 +16,15 @@ async fn main() {
14
16
15
17
let doc = OpenApi :: new ( "test api" , "0.0.1" ) . merge_router ( & router) ;
16
18
19
+ let cors = Cors :: new ( )
20
+ . allow_origin ( "*" )
21
+ . allow_methods ( vec ! [ Method :: GET , Method :: POST , Method :: DELETE ] )
22
+ . into_handler ( ) ;
23
+
17
24
let router = router
18
25
. push ( doc. into_router ( "/api-doc/openapi.json" ) )
19
- . push ( SwaggerUi :: new ( "/api-doc/openapi.json" ) . into_router ( "ui" ) ) ;
26
+ . push ( SwaggerUi :: new ( "/api-doc/openapi.json" ) . into_router ( "ui" ) )
27
+ . hoop ( cors) ;
20
28
21
29
let acceptor = TcpListener :: new ( "127.0.0.1:5800" ) . bind ( ) . await ;
22
30
Server :: new ( acceptor) . serve ( router) . await ;
Original file line number Diff line number Diff line change 1
1
<script >
2
- import Counter from " ./Counter.svelte" ;
3
- import welcome from " $lib/images/svelte-welcome.webp" ;
4
- import welcome_fallback from " $lib/images/svelte-welcome.png" ;
5
- import { BaseAPI , Configuration } from " ../api" ;
2
+ import { Configuration , DefaultApi } from " ../api" ;
3
+ import { onMount } from " svelte" ;
6
4
7
- const config = new Configuration ({
8
- basePath: " http://localhost:5800" ,
9
- });
5
+ let test = " this is a test" ;
6
+
7
+ onMount (async () => {
8
+ console .log (" onMount" );
9
+
10
+ const config = new Configuration ({
11
+ basePath: " http://localhost:5800" ,
12
+ });
13
+
14
+ const api = new DefaultApi (config);
10
15
11
- const api = new BaseAPI (config);
16
+ test = await api.
17
+ });
12
18
</script >
13
19
14
20
<svelte:head >
18
24
19
25
<section >
20
26
<h1 >
21
- <span class =" welcome" >
22
- <picture >
23
- <source srcset ={welcome } type =" image/webp" />
24
- <img src ={welcome_fallback } alt =" Welcome" />
25
- </picture >
26
- </span >
27
-
28
- to your new<br />SvelteKit app
27
+ {test }
29
28
</h1 >
30
-
31
- <h2 >
32
- try editing <strong >src/routes/+page.svelte</strong >
33
- </h2 >
34
-
35
- <Counter />
36
29
</section >
37
30
38
31
<style >
47
40
h1 {
48
41
width : 100% ;
49
42
}
50
-
51
- .welcome {
52
- display : block ;
53
- position : relative ;
54
- width : 100% ;
55
- height : 0 ;
56
- padding : 0 0 calc (100% * 495 / 2048 ) 0 ;
57
- }
58
-
59
- .welcome img {
60
- position : absolute ;
61
- width : 100% ;
62
- height : 100% ;
63
- top : 0 ;
64
- display : block ;
65
- }
66
43
</style >
You can’t perform that action at this time.
0 commit comments