@@ -39,7 +39,13 @@ pub(crate) async fn pre_render_static_routes(
39
39
let address = & address;
40
40
let port = & port;
41
41
42
- tracing:: info!( "Running SSG at http://{address}:{port} for {server_exe:?}" ) ;
42
+ let url = if let Some ( base_path) = builder. build . base_path ( ) {
43
+ format ! ( "http://{address}:{port}/{base_path}" )
44
+ } else {
45
+ format ! ( "http://{address}:{port}" )
46
+ } ;
47
+
48
+ tracing:: info!( "Running SSG at {url} for {server_exe:?}" ) ;
43
49
44
50
let vars = builder. child_environment_variables (
45
51
devserver_ip,
@@ -71,7 +77,7 @@ pub(crate) async fn pre_render_static_routes(
71
77
) ;
72
78
73
79
let request = reqwest_client
74
- . post ( format ! ( "http://{address}:{port }/api/static_routes" ) )
80
+ . post ( format ! ( "{url }/api/static_routes" ) )
75
81
. body ( "{}" . to_string ( ) )
76
82
. send ( )
77
83
. await ;
@@ -102,34 +108,37 @@ pub(crate) async fn pre_render_static_routes(
102
108
// Create a pool of futures that cache each route
103
109
let mut resolved_routes = routes
104
110
. into_iter ( )
105
- . map ( |route| async move {
106
- tracing:: info!( "Rendering {route} for SSG" ) ;
107
-
108
- // For each route, ping the server to force it to cache the response for ssg
109
- let request = reqwest_client
110
- . get ( format ! ( "http://{address}:{port}{route}" ) )
111
- . header ( "Accept" , "text/html" )
112
- . send ( )
113
- . await ?;
114
-
115
- // If it takes longer than 30 seconds to resolve the route, log a warning
116
- let warning_task = tokio:: spawn ( {
117
- let route = route. clone ( ) ;
118
- async move {
119
- tokio:: time:: sleep ( Duration :: from_secs ( 30 ) ) . await ;
120
- tracing:: warn!( "Route {route} has been rendering for 30 seconds" ) ;
121
- }
122
- } ) ;
123
-
124
- // Wait for the streaming response to completely finish before continuing. We don't use the html it returns directly
125
- // because it may contain artifacts of intermediate streaming steps while the page is loading. The SSG app should write
126
- // the final clean HTML to the disk automatically after the request completes.
127
- let _html = request. text ( ) . await ?;
128
-
129
- // Cancel the warning task if it hasn't already run
130
- warning_task. abort ( ) ;
131
-
132
- Ok :: < _ , reqwest:: Error > ( route)
111
+ . map ( |route| {
112
+ let url = url. clone ( ) ;
113
+ async move {
114
+ tracing:: info!( "Rendering {route} for SSG" ) ;
115
+
116
+ // For each route, ping the server to force it to cache the response for ssg
117
+ let request = reqwest_client
118
+ . get ( format ! ( "{url}{route}" ) )
119
+ . header ( "Accept" , "text/html" )
120
+ . send ( )
121
+ . await ?;
122
+
123
+ // If it takes longer than 30 seconds to resolve the route, log a warning
124
+ let warning_task = tokio:: spawn ( {
125
+ let route = route. clone ( ) ;
126
+ async move {
127
+ tokio:: time:: sleep ( Duration :: from_secs ( 30 ) ) . await ;
128
+ tracing:: warn!( "Route {route} has been rendering for 30 seconds" ) ;
129
+ }
130
+ } ) ;
131
+
132
+ // Wait for the streaming response to completely finish before continuing. We don't use the html it returns directly
133
+ // because it may contain artifacts of intermediate streaming steps while the page is loading. The SSG app should write
134
+ // the final clean HTML to the disk automatically after the request completes.
135
+ let _html = request. text ( ) . await ?;
136
+
137
+ // Cancel the warning task if it hasn't already run
138
+ warning_task. abort ( ) ;
139
+
140
+ Ok :: < _ , reqwest:: Error > ( route)
141
+ }
133
142
} )
134
143
. collect :: < FuturesUnordered < _ > > ( ) ;
135
144
0 commit comments