@@ -47,6 +47,9 @@ pub struct Project {
47
47
pub hash_file : HashFile ,
48
48
pub hash_files : bool ,
49
49
pub js_minify : bool ,
50
+ pub server_fn_prefix : Option < String > ,
51
+ pub disable_server_fn_hash : bool ,
52
+ pub server_fn_mod_path : bool ,
50
53
}
51
54
52
55
impl Debug for Project {
@@ -64,6 +67,9 @@ impl Debug for Project {
64
67
. field ( "site" , & self . site )
65
68
. field ( "end2end" , & self . end2end )
66
69
. field ( "assets" , & self . assets )
70
+ . field ( "server_fn_prefix" , & self . server_fn_prefix )
71
+ . field ( "disable_server_fn_hash" , & self . disable_server_fn_hash )
72
+ . field ( "server_fn_mod_path" , & self . server_fn_mod_path )
67
73
. finish_non_exhaustive ( )
68
74
}
69
75
}
@@ -126,6 +132,9 @@ impl Project {
126
132
hash_file,
127
133
hash_files : config. hash_files ,
128
134
js_minify : cli. release && cli. js_minify && config. js_minify ,
135
+ server_fn_prefix : config. server_fn_prefix ,
136
+ disable_server_fn_hash : config. disable_server_fn_hash ,
137
+ server_fn_mod_path : config. server_fn_mod_path ,
129
138
} ;
130
139
resolved. push ( Arc :: new ( proj) ) ;
131
140
}
@@ -159,7 +168,16 @@ impl Project {
159
168
vec. push ( ( "LEPTOS_HASH_FILE_NAME" , self . hash_file . rel . to_string ( ) ) ) ;
160
169
}
161
170
if self . watch {
162
- vec. push ( ( "LEPTOS_WATCH" , "true" . to_string ( ) ) )
171
+ vec. push ( ( "LEPTOS_WATCH" , true . to_string ( ) ) )
172
+ }
173
+ if let Some ( prefix) = self . server_fn_prefix . as_ref ( ) {
174
+ vec. push ( ( "SERVER_FN_PREFIX" , prefix. clone ( ) ) ) ;
175
+ }
176
+ if self . disable_server_fn_hash {
177
+ vec. push ( ( "DISABLE_SERVER_FN_HASH" , true . to_string ( ) ) ) ;
178
+ }
179
+ if self . server_fn_mod_path {
180
+ vec. push ( ( "SERVER_FN_MOD_PATH" , true . to_string ( ) ) ) ;
163
181
}
164
182
vec
165
183
}
@@ -226,6 +244,35 @@ pub struct ProjectConfig {
226
244
#[ serde( default ) ]
227
245
pub bin_default_features : bool ,
228
246
247
+ /// The default prefix to use for server functions when generating API routes. Can be
248
+ /// overridden for individual functions using `#[server(prefix = "...")]` as usual.
249
+ ///
250
+ /// This is useful to override the default prefix (`/api`) for all server functions without
251
+ /// needing to manually specify via `#[server(prefix = "...")]` on every server function.
252
+ #[ serde( default ) ]
253
+ pub server_fn_prefix : Option < String > ,
254
+
255
+ /// Whether to disable appending the server functions' hashes to the end of their API names.
256
+ ///
257
+ /// This is useful when an app's client side needs a stable server API. For example, shipping
258
+ /// the CSR WASM binary in a Tauri app. Tauri app releases are dependent on each platform's
259
+ /// distribution method (e.g., the Apple App Store or the Google Play Store), which typically
260
+ /// are much slower than the frequency at which a website can be updated. In addition, it's
261
+ /// common for users to not have the latest app version installed. In these cases, the CSR WASM
262
+ /// app would need to be able to continue calling the backend server function API, so the API
263
+ /// path needs to be consistent and not have a hash appended.
264
+ #[ serde( default ) ]
265
+ pub disable_server_fn_hash : bool ,
266
+
267
+ /// Include the module path of the server function in the API route. This is an alternative
268
+ /// strategy to prevent duplicate server function API routes (the default strategy is to add
269
+ /// a hash to the end of the route). Each element of the module path will be separated by a `/`.
270
+ /// For example, a server function with a fully qualified name of `parent::child::server_fn`
271
+ /// would have an API route of `/api/parent/child/server_fn` (possibly with a
272
+ /// different prefix and a hash suffix depending on the values of the other server fn configs).
273
+ #[ serde( default ) ]
274
+ server_fn_mod_path : bool ,
275
+
229
276
#[ serde( skip) ]
230
277
pub config_dir : Utf8PathBuf ,
231
278
#[ serde( skip) ]
0 commit comments