@@ -1143,6 +1143,19 @@ function start! end
1143
1143
1144
1144
function start! (mod:: Module = Main, ip:: IP4 = ip4_cli (Main. ARGS );
1145
1145
threads:: Int64 = 1 , router_threads:: UnitRange{Int64} = - 2 : threads)
1146
+
1147
+ # Inject bindings we will use into the module
1148
+ if ! isdefined (mod, :server )
1149
+ Core. eval (mod, :(global server, data, routes))
1150
+
1151
+ # Switch to the latest world where the bindings are available
1152
+ invokelatest (_start!, mod, ip, threads, router_threads)
1153
+ else
1154
+ _start! (mod, ip, threads, router_threads)
1155
+ end
1156
+ end
1157
+
1158
+ function _start! (mod:: Module , ip:: IP4 , threads:: Int64 , router_threads:: UnitRange{Int64} )
1146
1159
IP = Sockets. InetAddr (parse (IPAddr, ip. ip), ip. port)
1147
1160
server:: Sockets.TCPServer = Sockets. listen (IP)
1148
1161
mod. server = server
@@ -1210,6 +1223,7 @@ function generate_router(mod::Module, ip::IP4)
1210
1223
mod. routes = Vector {AbstractRoute} ()
1211
1224
loaded = []
1212
1225
for name in server_ns
1226
+ isdefined (mod, name) || continue
1213
1227
f = getfield (mod, name)
1214
1228
T = typeof (f)
1215
1229
if T <: AbstractExtension
0 commit comments