Skip to content

Commit e9142df

Browse files
authored
Merge pull request #17 from supabase/add-health-endpoint
fix: added a health check endpoint to the service
2 parents 8cfbd2d + adad8dc commit e9142df

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

base/src/server.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ use std::net::SocketAddr;
88
use std::path::Path;
99
use std::str;
1010
use std::str::FromStr;
11+
use tokio::io::AsyncWriteExt;
1112
use tokio::net::{TcpListener, TcpStream};
1213
use url::Url;
1314

1415
async fn process_stream(
15-
stream: TcpStream,
16+
mut stream: TcpStream,
1617
services_dir: String,
1718
mem_limit: u16,
1819
service_timeout: u16,
@@ -49,6 +50,15 @@ async fn process_stream(
4950
let host = str::from_utf8(host).unwrap_or("example.com"); // TODO: configure the default host
5051
let req_path = req.path.unwrap_or_default();
5152

53+
// if the request is for the health endpoint return a 200 OK response
54+
if req_path == "/_internal/health" {
55+
stream
56+
.write_all(b"HTTP/1.1 200 OK\r\ncontent-length: 0\r\n\r\n")
57+
.await?;
58+
stream.flush().await?;
59+
return Ok(());
60+
}
61+
5262
let url = Url::parse(&format!("http://{}{}", &host, &req_path).as_str())?;
5363
let path_segments = url.path_segments();
5464
if path_segments.is_none() {

0 commit comments

Comments
 (0)