http errors 404 and 415
This commit is contained in:
parent
3142e59450
commit
38dfe503d3
2 changed files with 26 additions and 21 deletions
|
|
@ -26,14 +26,6 @@ pub(crate) fn compile_function(
|
||||||
) -> Result<Chunk, CompilerErrorAtLine> {
|
) -> Result<Chunk, CompilerErrorAtLine> {
|
||||||
let fn_name = &function.name.lexeme;
|
let fn_name = &function.name.lexeme;
|
||||||
let mut compiler = Compiler::new(fn_name);
|
let mut compiler = Compiler::new(fn_name);
|
||||||
if is_http_method(fn_name) {
|
|
||||||
compiler.chunk.add_var(&TokenType::StringType, "path");
|
|
||||||
compiler.chunk.add_var(&TokenType::MapType, "query");
|
|
||||||
compiler.chunk.add_var(&TokenType::MapType, "headers");
|
|
||||||
compiler.vars.insert("path".to_string(), 0);
|
|
||||||
compiler.vars.insert("query".to_string(), 1);
|
|
||||||
compiler.vars.insert("headers".to_string(), 2);
|
|
||||||
}
|
|
||||||
for parm in &function.parameters {
|
for parm in &function.parameters {
|
||||||
let name = parm.name.lexeme.clone();
|
let name = parm.name.lexeme.clone();
|
||||||
let var_index = compiler.chunk.add_var(&parm.var_type, &parm.name.lexeme);
|
let var_index = compiler.chunk.add_var(&parm.var_type, &parm.name.lexeme);
|
||||||
|
|
@ -44,10 +36,6 @@ pub(crate) fn compile_function(
|
||||||
Ok(compiler.compile(&function.body, registry, namespace)?)
|
Ok(compiler.compile(&function.body, registry, namespace)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_http_method(name: &str) -> bool {
|
|
||||||
vec!["get", "post", "put", "delete", "patch"].contains(&name)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn compile_in_namespace(
|
pub(crate) fn compile_in_namespace(
|
||||||
ast: &Vec<Statement>,
|
ast: &Vec<Statement>,
|
||||||
namespace: Option<&str>,
|
namespace: Option<&str>,
|
||||||
|
|
|
||||||
31
src/main.rs
31
src/main.rs
|
|
@ -37,7 +37,9 @@ async fn main() -> Result<(), crudlang::errors::Error> {
|
||||||
axum::serve(listener, app).await.map_err(map_underlying())?;
|
axum::serve(listener, app).await.map_err(map_underlying())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(Platform("No source files found or compilation error".to_string()))
|
Err(Platform(
|
||||||
|
"No source files found or compilation error".to_string(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,16 +64,31 @@ async fn handle_any(
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let component = format!("{}/web.{}", &uri.path()[1..], method);
|
let component = format!("{}/web", &uri.path()[1..]);
|
||||||
|
let function_qname = format!("{}.{}", component, method);
|
||||||
|
|
||||||
let mut headers = HashMap::new();
|
let mut headers = HashMap::new();
|
||||||
for (k, v) in req.headers().iter() {
|
for (k, v) in req.headers().iter() {
|
||||||
headers.insert(k.to_string(), v.to_str().unwrap().to_string());
|
headers.insert(k.to_string(), v.to_str().unwrap().to_string());
|
||||||
}
|
}
|
||||||
Ok(Json(
|
let path = &req.uri().to_string();
|
||||||
interpret_async(&state.registry, &component, &req.uri().to_string(), query_params, headers)
|
match interpret_async(
|
||||||
|
&state.registry,
|
||||||
|
&function_qname,
|
||||||
|
path,
|
||||||
|
query_params,
|
||||||
|
headers,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
{
|
||||||
.to_string(),
|
Ok(value) => Ok(Json(value.to_string())),
|
||||||
))
|
Err(e) => {
|
||||||
|
// url checks out but function for method not found
|
||||||
|
if state.registry.get(&format!("{}.main",component)).is_some() {
|
||||||
|
Err(StatusCode::METHOD_NOT_ALLOWED)
|
||||||
|
} else {
|
||||||
|
Err(StatusCode::NOT_FOUND)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue