1
1
use crate :: service:: ServiceContext ;
2
2
use api_docs:: ApiDocs ;
3
3
use log:: info;
4
- use rocket:: fs:: FileServer ;
5
4
use rocket:: http:: { Method , Status } ;
6
5
use rocket:: { catch, catchers, routes, Build , Config , Request , Rocket } ;
7
6
use rocket_cors:: { AllowedHeaders , AllowedOrigins , CorsOptions } ;
@@ -17,6 +16,7 @@ use crate::constants::MAX_FILE_SIZE_BYTES;
17
16
use crate :: CONFIG ;
18
17
use rocket:: data:: ByteUnit ;
19
18
use rocket:: figment:: Figment ;
19
+ use rocket:: fs:: FileServer ;
20
20
use rocket:: serde:: json:: Json ;
21
21
use serde_json:: json;
22
22
@@ -75,16 +75,16 @@ pub fn rocket_main(context: ServiceContext) -> Rocket<Build> {
75
75
76
76
let rocket = rocket:: custom ( config)
77
77
. attach ( cors. clone ( ) )
78
- . mount ( "/" , rocket_cors:: catch_all_options_routes ( ) )
78
+ . mount ( "/api/ " , rocket_cors:: catch_all_options_routes ( ) )
79
79
. register ( "/" , catchers ! [ default_catcher, not_found] )
80
80
. manage ( context)
81
81
. manage ( cors)
82
- . mount ( "/exit" , routes ! [ handlers:: exit] )
83
- . mount ( "/currencies" , routes ! [ handlers:: currencies] )
84
- . mount ( "/overview" , routes ! [ handlers:: overview] )
85
- . mount ( "/search" , routes ! [ handlers:: search] )
82
+ . mount ( "/api/ exit" , routes ! [ handlers:: exit] )
83
+ . mount ( "/api/ currencies" , routes ! [ handlers:: currencies] )
84
+ . mount ( "/api/ overview" , routes ! [ handlers:: overview] )
85
+ . mount ( "/api/ search" , routes ! [ handlers:: search] )
86
86
. mount (
87
- "/identity" ,
87
+ "/api/ identity" ,
88
88
routes ! [
89
89
handlers:: identity:: create_identity,
90
90
handlers:: identity:: change_identity,
@@ -100,11 +100,7 @@ pub fn rocket_main(context: ServiceContext) -> Rocket<Build> {
100
100
] ,
101
101
)
102
102
. mount (
103
- & CONFIG . frontend_url_path ,
104
- FileServer :: from ( & CONFIG . frontend_serve_folder ) ,
105
- )
106
- . mount (
107
- "/contacts" ,
103
+ "/api/contacts" ,
108
104
routes ! [
109
105
handlers:: contacts:: new_contact,
110
106
handlers:: contacts:: edit_contact,
@@ -116,7 +112,7 @@ pub fn rocket_main(context: ServiceContext) -> Rocket<Build> {
116
112
] ,
117
113
)
118
114
. mount (
119
- "/company" ,
115
+ "/api/ company" ,
120
116
routes ! [
121
117
handlers:: company:: check_companies_in_dht,
122
118
handlers:: company:: list,
@@ -131,7 +127,7 @@ pub fn rocket_main(context: ServiceContext) -> Rocket<Build> {
131
127
] ,
132
128
)
133
129
. mount (
134
- "/bill" ,
130
+ "/api/ bill" ,
135
131
routes ! [
136
132
handlers:: bill:: all_bills_from_all_identities,
137
133
handlers:: bill:: issue_bill,
@@ -166,14 +162,14 @@ pub fn rocket_main(context: ServiceContext) -> Rocket<Build> {
166
162
] ,
167
163
)
168
164
. mount (
169
- "/quote" ,
165
+ "/api/ quote" ,
170
166
routes ! [
171
167
handlers:: quotes:: return_quote,
172
168
handlers:: quotes:: accept_quote
173
169
] ,
174
170
)
175
171
. mount (
176
- "/" ,
172
+ "/api/ " ,
177
173
routes ! [
178
174
handlers:: notifications:: list_notifications,
179
175
handlers:: notifications:: mark_notification_done,
@@ -183,9 +179,15 @@ pub fn rocket_main(context: ServiceContext) -> Rocket<Build> {
183
179
] ,
184
180
)
185
181
. mount (
186
- "/" ,
182
+ "/api/ " ,
187
183
SwaggerUi :: new ( "/swagger-ui/<_..>" ) . url ( "/api-docs/openapi.json" , ApiDocs :: openapi ( ) ) ,
188
- ) ;
184
+ )
185
+ . mount (
186
+ & CONFIG . frontend_url_path ,
187
+ FileServer :: from ( & CONFIG . frontend_serve_folder ) . rank ( 5 ) ,
188
+ )
189
+ // TODO: fall back to index, but serve static files first
190
+ . mount ( & CONFIG . frontend_url_path , routes ! [ handlers:: serve_frontend] ) ;
189
191
190
192
info ! ( "HTTP Server Listening on {}" , conf. http_listen_url( ) ) ;
191
193
0 commit comments