1
Fork 0

cors with timeout

This commit is contained in:
Jan-Erik Rediger 2024-05-25 00:07:10 +02:00
parent 4bc4a07ce0
commit 8d23222e95
4 changed files with 27 additions and 7 deletions

View file

@ -9,6 +9,6 @@ libc = "0.2.155"
serde = { version = "1.0.202", features = ["derive"] }
tempfile = "3.10.1"
tokio = { version = "1.37.0", features = ["rt-multi-thread"] }
tower-http = { version = "0.5.2", features = ["trace"] }
tower-http = { version = "0.5.2", features = ["trace", "cors"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

View file

@ -9,6 +9,7 @@ use axum::{
};
use serde::{Deserialize, Serialize};
use tower_http::trace::TraceLayer;
use tower_http::cors::CorsLayer;
use tracing::info_span;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
@ -65,7 +66,9 @@ async fn main() {
.with(tracing_subscriber::fmt::layer())
.init();
let app = Router::new().route("/v1/exec", post(exec)).layer(
let app = Router::new().route("/v1/exec", post(exec))
.layer(CorsLayer::permissive())
.layer(
TraceLayer::new_for_http().make_span_with(|request: &Request<_>| {
let matched_path = request
.extensions()

View file

@ -27,7 +27,7 @@ const STATIC_ARGS: &[&str] = &[
const HARE_COMMAND: &str = "/usr/local/bin/hare";
/// Default command timeout in seconds.
const DEFAULT_TIMEOUT: u32 = 10;
const DEFAULT_TIMEOUT: u32 = 30;
fn passwd_files(uid: u32, gid: u32) -> (NamedTempFile, NamedTempFile, Vec<String>) {
let uid = uid.to_string();
@ -96,6 +96,7 @@ fn shared_app_dir() -> (TempDir, Vec<String>) {
fn command(app_file: &str) -> Vec<String> {
vec![
"/usr/bin/timeout".to_string(), DEFAULT_TIMEOUT.to_string(),
HARE_COMMAND.to_string(),
"run".to_string(),
app_file.to_string(),

View file

@ -46,13 +46,29 @@
</style>
</head>
<body>
<codapi-settings url="http://localhost:8080/v1"></codapi-settings>
<codapi-settings url="http://joltrast:8080/v1"></codapi-settings>
<div id="playground">
<pre class="code"><code contenteditable="true">msg = "Hello, World!"
print(msg)</code></pre>
<pre class="code"><code contenteditable="true">
use fmt;
use time;
export fn main() void = {
const greetings = [
"Hello, world!",
"¡Hola Mundo!",
"Γειά σου Κόσμε!",
"Привіт, світ!",
"こんにちは世界!",
];
for (let i = 0z; i < len(greetings); i+= 1) {
fmt::println(greetings[i])!;
time::sleep(1 * time::SECOND);
};
};
</code></pre>
</div>
<codapi-snippet sandbox="python" editor="basic" selector="#playground .code">
<codapi-snippet sandbox="hare" editor="basic" selector="#playground .code">
</codapi-snippet>
</body>
</html>