Wire up the API routes and start playing with those.
Nothing actually _running_ yet of course.
This commit is contained in:
parent
6af9c32de4
commit
57805bdb01
|
@ -22,6 +22,8 @@ pub mod v1 {
|
|||
description: Option<String>,
|
||||
/// The trigger for executing the project
|
||||
trigger: TriggerType,
|
||||
/// Optional inline script, otherwise Geoffrey will look for a file in the repo
|
||||
script: Option<String>,
|
||||
}
|
||||
|
||||
impl Project {
|
||||
|
|
|
@ -25,6 +25,7 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
let state = AppState::new();
|
||||
let mut app = tide::with_state(state);
|
||||
routes::views::register(&mut app);
|
||||
routes::api::register(&mut app);
|
||||
|
||||
if let Some(fd) = std::env::var("LISTEN_FD")
|
||||
.ok()
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* API routes
|
||||
*/
|
||||
use crate::state::*;
|
||||
use log::*;
|
||||
use serde::Deserialize;
|
||||
use tide::{Request, Server};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
struct ApiParams {
|
||||
#[serde(rename = "return")]
|
||||
redirect: Option<String>,
|
||||
}
|
||||
|
||||
pub fn register(app: &mut Server<AppState<'static>>) {
|
||||
let mut api = tide::with_state(app.state().clone());
|
||||
api.at("project/:slug/run").get(run_project);
|
||||
app.at("/api").nest(api);
|
||||
}
|
||||
|
||||
async fn run_project(req: Request<AppState<'static>>) -> tide::Result {
|
||||
debug!("Running project: {:?}", req.param("slug"));
|
||||
let qs: ApiParams = req.query()?;
|
||||
if let Some(redirect) = &qs.redirect {
|
||||
info!("Redirecting back to {}", redirect);
|
||||
|
||||
if !redirect.starts_with("/") {
|
||||
warn!("Unsafe redirect, ignoring: {:?}", redirect);
|
||||
}
|
||||
return Ok(tide::Redirect::new(&redirect).into());
|
||||
}
|
||||
Ok("Run".into())
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
pub mod api;
|
||||
/**
|
||||
* This module contains all the re-exported routes for different aspects of Geoffrey
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue