ci: fix vweb failures (restore the ability to *force* vweb to listen to *only* local interfaces)
							parent
							
								
									3d46005195
								
							
						
					
					
						commit
						ef5ea0ef21
					
				| 
						 | 
					@ -44,7 +44,7 @@ fn main() {
 | 
				
			||||||
		global_config: config
 | 
							global_config: config
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	eprintln('>> webserver: started on http://localhost:$app.port/ , with maximum runtime of $app.timeout milliseconds.')
 | 
						eprintln('>> webserver: started on http://localhost:$app.port/ , with maximum runtime of $app.timeout milliseconds.')
 | 
				
			||||||
	vweb.run_at(app, 'localhost', http_port)
 | 
						vweb.run_at(app, host: 'localhost', port: http_port, family: .ip) ?
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// pub fn (mut app App) init_server() {
 | 
					// pub fn (mut app App) init_server() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -378,21 +378,29 @@ interface DbInterface {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// run - start a new VWeb server, listening to all available addresses, at the specified `port`
 | 
					// run - start a new VWeb server, listening to all available addresses, at the specified `port`
 | 
				
			||||||
pub fn run<T>(global_app &T, port int) {
 | 
					pub fn run<T>(global_app &T, port int) {
 | 
				
			||||||
	run_at<T>(global_app, '', port)
 | 
						run_at<T>(global_app, host: '', port: port, family: .ip6) or { panic(err.msg()) }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[params]
 | 
				
			||||||
 | 
					pub struct RunParams {
 | 
				
			||||||
 | 
						host   string
 | 
				
			||||||
 | 
						port   int = 8080
 | 
				
			||||||
 | 
						family net.AddrFamily = .ip6 // use `family: .ip, host: 'localhost'` when you want it to bind only to 127.0.0.1
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// run_at - start a new VWeb server, listening only on a specific address `host`, at the specified `port`
 | 
					// run_at - start a new VWeb server, listening only on a specific address `host`, at the specified `port`
 | 
				
			||||||
// Example: `vweb.run_at(app, 'localhost', 8099)`
 | 
					// Example: `vweb.run_at(app, 'localhost', 8099)`
 | 
				
			||||||
[manualfree]
 | 
					[manualfree]
 | 
				
			||||||
pub fn run_at<T>(global_app &T, host string, port int) {
 | 
					pub fn run_at<T>(global_app &T, params RunParams) ? {
 | 
				
			||||||
	mut l := net.listen_tcp(.ip6, '$host:$port') or { panic('failed to listen $err.code $err') }
 | 
						mut l := net.listen_tcp(params.family, '$params.host:$params.port') or {
 | 
				
			||||||
 | 
							return error('failed to listen $err.code $err')
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Parsing methods attributes
 | 
						// Parsing methods attributes
 | 
				
			||||||
	mut routes := map[string]Route{}
 | 
						mut routes := map[string]Route{}
 | 
				
			||||||
	$for method in T.methods {
 | 
						$for method in T.methods {
 | 
				
			||||||
		http_methods, route_path := parse_attrs(method.name, method.attrs) or {
 | 
							http_methods, route_path := parse_attrs(method.name, method.attrs) or {
 | 
				
			||||||
			eprintln('error parsing method attributes: $err')
 | 
								return error('error parsing method attributes: $err')
 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		routes[method.name] = Route{
 | 
							routes[method.name] = Route{
 | 
				
			||||||
| 
						 | 
					@ -400,7 +408,8 @@ pub fn run_at<T>(global_app &T, host string, port int) {
 | 
				
			||||||
			path: route_path
 | 
								path: route_path
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	println('[Vweb] Running app on http://localhost:$port')
 | 
						host := if params.host == '' { 'localhost' } else { params.host }
 | 
				
			||||||
 | 
						println('[Vweb] Running app on http://$host:$params.port/')
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		// Create a new app object for each connection, copy global data like db connections
 | 
							// Create a new app object for each connection, copy global data like db connections
 | 
				
			||||||
		mut request_app := &T{}
 | 
							mut request_app := &T{}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue