mirror of
https://github.com/zaphar/Heracles.git
synced 2025-07-23 12:39:50 -04:00
Compare commits
3 Commits
06778ccc94
...
fc06c85356
Author | SHA1 | Date | |
---|---|---|---|
fc06c85356 | |||
e607ce53ea | |||
f5609bd6b0 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -12,3 +12,8 @@ Cargo.lock
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
|
||||
# Added by cargo
|
||||
|
||||
/target
|
||||
|
20
Cargo.toml
Normal file
20
Cargo.toml
Normal file
@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "heracles"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
async-io = "2.3.1"
|
||||
axum = "0.7.4"
|
||||
clap = { version = "4.4.18", features = ["derive"] }
|
||||
maud = { version = "0.26.0", features = ["axum"] }
|
||||
prometheus-http-api = "0.2.0"
|
||||
serde = { version = "1.0.196", features = ["derive"] }
|
||||
serde_json = "1.0.113"
|
||||
serde_yaml = "0.9.31"
|
||||
smol = "2.0.0"
|
||||
smol-axum = "0.1.0"
|
||||
smol-macros = "0.1.0"
|
46
src/main.rs
Normal file
46
src/main.rs
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright 2021 Jeremy Wall
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
use std::io;
|
||||
use std::net::TcpListener;
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_io::Async;
|
||||
use axum::{self, routing::*, Router};
|
||||
use clap::{self, Parser};
|
||||
use smol_macros::main;
|
||||
|
||||
mod routes;
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Cli {
|
||||
#[arg(long)]
|
||||
listen: Option<std::net::SocketAddr>,
|
||||
}
|
||||
|
||||
main! {
|
||||
async fn main(ex: &Arc<smol_macros::Executor<'_>>) -> io::Result<()> {
|
||||
let args = Cli::parse();
|
||||
let router = Router::new()
|
||||
// JSON api endpoints
|
||||
.nest("/api", routes::mk_api_routes())
|
||||
// HTMX ui component endpoints
|
||||
.nest("/ui", routes::mk_ui_routes())
|
||||
.route("/", get(routes::index));
|
||||
let socket_addr = args.listen.unwrap_or("127.0.0.1:3000".parse().unwrap());
|
||||
// TODO(jwall): Take this from clap arguments
|
||||
let listener = Async::<TcpListener>::bind(socket_addr).unwrap();
|
||||
smol_axum::serve(ex.clone(), listener, router).await
|
||||
}
|
||||
}
|
36
src/routes.rs
Normal file
36
src/routes.rs
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright 2021 Jeremy Wall
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
use maud::{html, Markup};
|
||||
use axum::Router;
|
||||
|
||||
pub fn mk_api_routes() -> Router {
|
||||
Router::new()
|
||||
}
|
||||
|
||||
pub fn mk_ui_routes() -> Router {
|
||||
Router::new()
|
||||
}
|
||||
|
||||
pub async fn index() -> Markup {
|
||||
html! {
|
||||
html {
|
||||
head {
|
||||
title { ("Heracles - Prometheus Unshackled") }
|
||||
}
|
||||
body {
|
||||
("hello world")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user