mirror of https://github.com/mastodon/flodgatt
Unix sockets (#81)
* Fix unix socket permission issue * Add support for Unix sockets * Update README and bump version
This commit is contained in:
parent
20b9c7b593
commit
0462267125
|
@ -404,7 +404,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flodgatt"
|
name = "flodgatt"
|
||||||
version = "0.4.5"
|
version = "0.4.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"dotenv 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"dotenv 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "flodgatt"
|
name = "flodgatt"
|
||||||
description = "A blazingly fast drop-in replacement for the Mastodon streaming api server"
|
description = "A blazingly fast drop-in replacement for the Mastodon streaming api server"
|
||||||
version = "0.4.5"
|
version = "0.4.6"
|
||||||
authors = ["Daniel Long Sockwell <daniel@codesections.com", "Julian Laubstein <contact@julianlaubstein.de>"]
|
authors = ["Daniel Long Sockwell <daniel@codesections.com", "Julian Laubstein <contact@julianlaubstein.de>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,9 @@ Note that the default values for the `postgres` connection do not correspond to
|
||||||
used in production. Thus, you will need to configure the connection either env vars or a `.env`
|
used in production. Thus, you will need to configure the connection either env vars or a `.env`
|
||||||
file if you intend to connect Flóðgátt to a production database.
|
file if you intend to connect Flóðgátt to a production database.
|
||||||
|
|
||||||
|
If you set the `SOCKET` environmental variable, you must set the nginx `proxy_pass` variable to
|
||||||
|
the same socket (with the file prefixed by `http://unix:`).
|
||||||
|
|
||||||
Additionally, note that connecting Flóðgátt to Postgres with the `ident` method requires running
|
Additionally, note that connecting Flóðgátt to Postgres with the `ident` method requires running
|
||||||
Flóðgátt as the user who owns the mastodon database (typically `mastodon`).
|
Flóðgátt as the user who owns the mastodon database (typically `mastodon`).
|
||||||
|
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -4,7 +4,8 @@ use flodgatt::{
|
||||||
redis_to_client_stream::{self, ClientAgent},
|
redis_to_client_stream::{self, ClientAgent},
|
||||||
};
|
};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use std::{collections::HashMap, env, net};
|
use std::{collections::HashMap, env, fs, net, os::unix::fs::PermissionsExt};
|
||||||
|
use tokio::net::UnixListener;
|
||||||
use warp::{path, ws::Ws2, Filter};
|
use warp::{path, ws::Ws2, Filter};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -59,6 +60,7 @@ fn main() {
|
||||||
let websocket_routes = ws::extract_user_or_reject(pg_conn.clone())
|
let websocket_routes = ws::extract_user_or_reject(pg_conn.clone())
|
||||||
.and(warp::ws::ws2())
|
.and(warp::ws::ws2())
|
||||||
.map(move |user: user::User, ws: Ws2| {
|
.map(move |user: user::User, ws: Ws2| {
|
||||||
|
warn!("Incoming request");
|
||||||
let token = user.access_token.clone();
|
let token = user.access_token.clone();
|
||||||
// Create a new ClientAgent
|
// Create a new ClientAgent
|
||||||
let mut client_agent = client_agent_ws.clone_with_shared_receiver();
|
let mut client_agent = client_agent_ws.clone_with_shared_receiver();
|
||||||
|
@ -85,17 +87,18 @@ fn main() {
|
||||||
.allow_methods(cfg.cors.allowed_methods)
|
.allow_methods(cfg.cors.allowed_methods)
|
||||||
.allow_headers(cfg.cors.allowed_headers);
|
.allow_headers(cfg.cors.allowed_headers);
|
||||||
|
|
||||||
let server_addr = net::SocketAddr::new(*cfg.address, cfg.port.0);
|
|
||||||
|
|
||||||
let health = warp::path!("api" / "v1" / "streaming" / "health").map(|| "OK");
|
let health = warp::path!("api" / "v1" / "streaming" / "health").map(|| "OK");
|
||||||
|
|
||||||
if let Some(socket) = &*cfg.unix_socket {
|
if let Some(socket) = &*cfg.unix_socket {
|
||||||
warn!("Using Unix sockets is a WIP that is currently unsupported and untested.");
|
warn!("Using Unix socket {}", socket);
|
||||||
std::fs::remove_file(socket).unwrap();
|
fs::remove_file(socket).unwrap_or_default();
|
||||||
use tokio::net::UnixListener;
|
|
||||||
let incoming = UnixListener::bind(socket).unwrap().incoming();
|
let incoming = UnixListener::bind(socket).unwrap().incoming();
|
||||||
|
|
||||||
|
fs::set_permissions(socket, PermissionsExt::from_mode(0o666)).unwrap();
|
||||||
|
|
||||||
warp::serve(health.or(websocket_routes.or(sse_routes).with(cors))).run_incoming(incoming);
|
warp::serve(health.or(websocket_routes.or(sse_routes).with(cors))).run_incoming(incoming);
|
||||||
} else {
|
} else {
|
||||||
|
let server_addr = net::SocketAddr::new(*cfg.address, cfg.port.0);
|
||||||
warp::serve(health.or(websocket_routes.or(sse_routes).with(cors))).run(server_addr);
|
warp::serve(health.or(websocket_routes.or(sse_routes).with(cors))).run(server_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue