summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2019-12-11 21:28:33 -0800
committerDessalines <tyhou13@gmx.com>2019-12-11 21:28:33 -0800
commit665dca80d00c3947a4838bbd468cfdcb9241ace5 (patch)
treed5cb8ac97b2ff27dbbfe72f2d7eaec4f797fe2a1
parent4cbfe6d0fc49fcaeaf95d1993ebe6b16fa49b1a3 (diff)
Moving front end routes from nginx to actix
- Fixes #363
-rw-r--r--ansible/templates/nginx.conf13
-rw-r--r--server/src/main.rs43
-rw-r--r--ui/src/index.tsx2
-rw-r--r--ui/src/utils.ts2
4 files changed, 51 insertions, 9 deletions
diff --git a/ansible/templates/nginx.conf b/ansible/templates/nginx.conf
index c8afcf4b..a484594e 100644
--- a/ansible/templates/nginx.conf
+++ b/ansible/templates/nginx.conf
@@ -50,7 +50,6 @@ server {
client_max_body_size 50M;
location / {
- rewrite (\/(user|(?<!feeds\/)u\/|(?<!feeds\/)inbox|post|community|(?<!feeds\/)c\/|create_post|create_community|login|search|setup|sponsors|communities|modlog|home|password_change)+) /static/index.html break;
proxy_pass http://0.0.0.0:8536;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
@@ -73,4 +72,16 @@ server {
expires max;
}
}
+ # Anonymize IP addresses
+ # https://www.supertechcrew.com/anonymizing-logs-nginx-apache/
+ map $remote_addr $remote_addr_anon {
+ ~(?P<ip>\d+\.\d+\.\d+)\. $ip.0;
+ ~(?P<ip>[^:]+:[^:]+): $ip::;
+ 127.0.0.1 $remote_addr;
+ ::1 $remote_addr;
+ default 0.0.0.0;
+ }
+ log_format main '$remote_addr_anon - $remote_user [$time_local] "$request" '
+ '$status $body_bytes_sent "$http_referer" "$http_user_agent"';
+ access_log /dev/stdout main;
}
diff --git a/server/src/main.rs b/server/src/main.rs
index cdcd7a65..98ce8e3f 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -198,20 +198,51 @@ fn main() {
HttpServer::new(move || {
App::new()
.data(server.clone())
+ // Front end routes
+ .service(actix_files::Files::new("/static", front_end_dir()))
+ .route("/", web::get().to(index))
+ .route(
+ "/home/type/{type}/sort/{sort}/page/{page}",
+ web::get().to(index),
+ )
+ .route("/login", web::get().to(index))
+ .route("/create_post", web::get().to(index))
+ .route("/create_community", web::get().to(index))
+ .route("/communities/page/{page}", web::get().to(index))
+ .route("/communities", web::get().to(index))
+ .route("/post/{id}/comment/{id2}", web::get().to(index))
+ .route("/post/{id}", web::get().to(index))
+ .route("/c/{name}/sort/{sort}/page/{page}", web::get().to(index))
+ .route("/c/{name}", web::get().to(index))
+ .route("/community/{id}", web::get().to(index))
+ .route(
+ "/u/{username}/view/{view}/sort/{sort}/page/{page}",
+ web::get().to(index),
+ )
+ .route("/u/{username}", web::get().to(index))
+ .route("/user/{id}", web::get().to(index))
+ .route("/inbox", web::get().to(index))
+ .route("/modlog/community/{community_id}", web::get().to(index))
+ .route("/modlog", web::get().to(index))
+ .route("/setup", web::get().to(index))
+ .route(
+ "/search/q/{q}/type/{type}/sort/{sort}/page/{page}",
+ web::get().to(index),
+ )
+ .route("/search", web::get().to(index))
+ .route("/sponsors", web::get().to(index))
+ .route("/password_change/{token}", web::get().to(index))
+ // Websocket
.service(web::resource("/api/v1/ws").to(chat_route))
- // .service(web::resource("/api/v1/rest").route(web::post().to(||{})))
- .service(web::resource("/").to(index))
+ // NodeInfo
.route("/nodeinfo/2.0.json", web::get().to(nodeinfo::node_info))
.route(
"/.well-known/nodeinfo",
web::get().to(nodeinfo::node_info_well_known),
)
+ // RSS
.route("/feeds/{type}/{name}.xml", web::get().to(feeds::get_feed))
- // TODO: probably need a different function for this (or just handle all of /feeds?
- // TODO: would be nice to use ListingType, but that doesnt include user
.route("/feeds/all.xml", web::get().to(feeds::get_all_feed))
- // static resources
- .service(actix_files::Files::new("/static", front_end_dir()))
})
.bind((settings.bind, settings.port))
.unwrap()
diff --git a/ui/src/index.tsx b/ui/src/index.tsx
index 2e50db88..41404f4b 100644
--- a/ui/src/index.tsx
+++ b/ui/src/index.tsx
@@ -38,11 +38,11 @@ class Index extends Component<any, any> {
<Navbar />
<div class="mt-4 p-0">
<Switch>
+ <Route exact path={`/`} component={Main} />
<Route
path={`/home/type/:type/sort/:sort/page/:page`}
component={Main}
/>
- <Route exact path={`/`} component={Main} />
<Route path={`/login`} component={Login} />
<Route path={`/create_post`} component={CreatePost} />
<Route path={`/create_community`} component={CreateCommunity} />
diff --git a/ui/src/utils.ts b/ui/src/utils.ts
index 1bbda3aa..98645fe3 100644
--- a/ui/src/utils.ts
+++ b/ui/src/utils.ts
@@ -197,7 +197,7 @@ export async function getPageTitle(url: string) {
export function debounce(
func: any,
- wait: number = 500,
+ wait: number = 1000,
immediate: boolean = false
) {
// 'private' variable for instance