(
&self,
inbound: TcpStream,
buffer: Vec<u8>,
port: u16,
h2: bool,
)
| 152 | |
| 153 | impl Proxy { |
| 154 | pub(crate) async fn handle_this_node( |
| 155 | &self, |
| 156 | inbound: TcpStream, |
| 157 | buffer: Vec<u8>, |
| 158 | port: u16, |
| 159 | h2: bool, |
| 160 | ) -> Result<()> { |
| 161 | if port != 80 { |
| 162 | bail!("Only port 80 is supported for this node"); |
| 163 | } |
| 164 | let stream = self.tls_accept(inbound, buffer, h2).await?; |
| 165 | let io = TokioIo::new(stream); |
| 166 | |
| 167 | let service = service_fn(|req: Request<Incoming>| async move { |
| 168 | // Only respond to GET / requests |
| 169 | if req.method() != hyper::Method::GET { |
| 170 | return empty_response(StatusCode::METHOD_NOT_ALLOWED); |
| 171 | } |
| 172 | if req.uri().path() == "/health" { |
| 173 | return empty_response(StatusCode::OK); |
| 174 | } |
| 175 | let path = req.uri().path().trim_start_matches("/.dstack"); |
| 176 | match path { |
| 177 | "/index" => { |
| 178 | let body = serde_json::json!({ |
| 179 | "type": "dstack gateway", |
| 180 | "paths": [ |
| 181 | "/index", |
| 182 | "/app-info", |
| 183 | "/acme-info", |
| 184 | ], |
| 185 | }); |
| 186 | json_response(&body) |
| 187 | } |
| 188 | "/app-info" => { |
| 189 | let agent = crate::dstack_agent().context("Failed to get dstack agent")?; |
| 190 | let app_info = agent.info().await.context("Failed to get app info")?; |
| 191 | json_response(&app_info) |
| 192 | } |
| 193 | "/acme-info" => { |
| 194 | let acme_info = self.acme_info(None).context("Failed to get acme info")?; |
| 195 | json_response(&acme_info) |
| 196 | } |
| 197 | _ => empty_response(StatusCode::NOT_FOUND), |
| 198 | } |
| 199 | }); |
| 200 | |
| 201 | http1::Builder::new() |
| 202 | .serve_connection(io, service) |
| 203 | .await |
| 204 | .context("Failed to serve HTTP connection")?; |
| 205 | |
| 206 | Ok(()) |
| 207 | } |
| 208 | |
| 209 | /// Deprecated legacy endpoint |
| 210 | pub(crate) async fn handle_health_check( |
no test coverage detected