make rust happy
Signed-off-by: Xe Iaso <me@christine.website>
This commit is contained in:
parent
8f187e325c
commit
e370af8bd5
60
src/main.rs
60
src/main.rs
|
@ -4,16 +4,17 @@ extern crate tracing;
|
||||||
use axum::{
|
use axum::{
|
||||||
body,
|
body,
|
||||||
extract::Extension,
|
extract::Extension,
|
||||||
http::header::{self, HeaderValue, CACHE_CONTROL, CONTENT_TYPE},
|
http::header::{self, HeaderValue, CONTENT_TYPE},
|
||||||
response::{Html, Response},
|
response::{Html, Response},
|
||||||
routing::get,
|
routing::{get, get_service},
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use hyper::StatusCode;
|
use hyper::StatusCode;
|
||||||
use prometheus::{Encoder, TextEncoder};
|
use prometheus::{Encoder, TextEncoder};
|
||||||
|
use sdnotify::SdNotify;
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env, io,
|
||||||
net::{IpAddr, SocketAddr},
|
net::{IpAddr, SocketAddr},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
@ -33,6 +34,8 @@ pub mod signalboost;
|
||||||
mod domainsocket;
|
mod domainsocket;
|
||||||
use domainsocket::*;
|
use domainsocket::*;
|
||||||
|
|
||||||
|
use crate::app::poke;
|
||||||
|
|
||||||
const APPLICATION_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
const APPLICATION_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
async fn healthcheck() -> &'static str {
|
async fn healthcheck() -> &'static str {
|
||||||
|
@ -109,8 +112,8 @@ async fn main() -> Result<()> {
|
||||||
.route("/metrics", get(metrics))
|
.route("/metrics", get(metrics))
|
||||||
.route(
|
.route(
|
||||||
"/sw.js",
|
"/sw.js",
|
||||||
axum::routing::get_service(ServeFile::new("./static/js/sw.js")).handle_error(
|
get_service(ServeFile::new("./static/js/sw.js")).handle_error(
|
||||||
|err: std::io::Error| async move {
|
|err: io::Error| async move {
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
format!("unhandled internal server error: {}", err),
|
format!("unhandled internal server error: {}", err),
|
||||||
|
@ -120,8 +123,8 @@ async fn main() -> Result<()> {
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/.well-known/assetlinks.json",
|
"/.well-known/assetlinks.json",
|
||||||
axum::routing::get_service(ServeFile::new("./static/assetlinks.json")).handle_error(
|
get_service(ServeFile::new("./static/assetlinks.json")).handle_error(
|
||||||
|err: std::io::Error| async move {
|
|err: io::Error| async move {
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
format!("unhandled internal server error: {}", err),
|
format!("unhandled internal server error: {}", err),
|
||||||
|
@ -131,8 +134,8 @@ async fn main() -> Result<()> {
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/robots.txt",
|
"/robots.txt",
|
||||||
axum::routing::get_service(ServeFile::new("./static/robots.txt")).handle_error(
|
get_service(ServeFile::new("./static/robots.txt")).handle_error(
|
||||||
|err: std::io::Error| async move {
|
|err: io::Error| async move {
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
format!("unhandled internal server error: {}", err),
|
format!("unhandled internal server error: {}", err),
|
||||||
|
@ -142,13 +145,14 @@ async fn main() -> Result<()> {
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/favicon.ico",
|
"/favicon.ico",
|
||||||
axum::routing::get_service(ServeFile::new("./static/favicon/favicon.ico"))
|
get_service(ServeFile::new("./static/favicon/favicon.ico")).handle_error(
|
||||||
.handle_error(|err: std::io::Error| async move {
|
|err: io::Error| async move {
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
format!("unhandled internal server error: {}", err),
|
format!("unhandled internal server error: {}", err),
|
||||||
)
|
)
|
||||||
}),
|
},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
// static pages
|
// static pages
|
||||||
.route("/", get(handlers::index))
|
.route("/", get(handlers::index))
|
||||||
|
@ -180,35 +184,31 @@ async fn main() -> Result<()> {
|
||||||
// static files
|
// static files
|
||||||
.nest(
|
.nest(
|
||||||
"/css",
|
"/css",
|
||||||
axum::routing::get_service(ServeDir::new("./css")).handle_error(
|
get_service(ServeDir::new("./css")).handle_error(|err: io::Error| async move {
|
||||||
|err: std::io::Error| async move {
|
(
|
||||||
(
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
format!("unhandled internal server error: {}", err),
|
||||||
format!("unhandled internal server error: {}", err),
|
)
|
||||||
)
|
}),
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.nest(
|
.nest(
|
||||||
"/static",
|
"/static",
|
||||||
axum::routing::get_service(ServeDir::new("./static")).handle_error(
|
get_service(ServeDir::new("./static")).handle_error(|err: io::Error| async move {
|
||||||
|err: std::io::Error| async move {
|
(
|
||||||
(
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
format!("unhandled internal server error: {}", err),
|
||||||
format!("unhandled internal server error: {}", err),
|
)
|
||||||
)
|
}),
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.layer(middleware);
|
.layer(middleware);
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
match sdnotify::SdNotify::from_env() {
|
match SdNotify::from_env() {
|
||||||
Ok(ref mut n) => {
|
Ok(ref mut n) => {
|
||||||
// shitty heuristic for detecting if we're running in prod
|
// shitty heuristic for detecting if we're running in prod
|
||||||
tokio::spawn(async {
|
tokio::spawn(async {
|
||||||
if let Err(why) = app::poke::the_cloud().await {
|
if let Err(why) = poke::the_cloud().await {
|
||||||
error!("Unable to poke the cloud: {}", why);
|
error!("Unable to poke the cloud: {}", why);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue