mirror of
https://github.com/zaphar/Heracles.git
synced 2025-07-23 12:39:50 -04:00
init: Scaffolding for axum serving
This commit is contained in:
parent
06778ccc94
commit
f5609bd6b0
5
.gitignore
vendored
5
.gitignore
vendored
@ -12,3 +12,8 @@ Cargo.lock
|
|||||||
|
|
||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
|
||||||
|
/target
|
||||||
|
19
Cargo.toml
Normal file
19
Cargo.toml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
[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"
|
||||||
|
smol = "2.0.0"
|
||||||
|
smol-axum = "0.1.0"
|
||||||
|
smol-macros = "0.1.0"
|
37
src/main.rs
Normal file
37
src/main.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// 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 smol_macros::main;
|
||||||
|
|
||||||
|
mod routes;
|
||||||
|
|
||||||
|
main! {
|
||||||
|
async fn main(ex: &Arc<smol_macros::Executor<'_>>) -> io::Result<()> {
|
||||||
|
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));
|
||||||
|
|
||||||
|
// TODO(jwall): Take this from clap arguments
|
||||||
|
let listener = Async::<TcpListener>::bind(([127, 0, 0, 1], 3000)).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