]> Untitled Git - lemmy.git/commitdiff
Moving front end routes from nginx to actix
authorDessalines <tyhou13@gmx.com>
Thu, 12 Dec 2019 05:28:33 +0000 (21:28 -0800)
committerDessalines <tyhou13@gmx.com>
Thu, 12 Dec 2019 05:28:33 +0000 (21:28 -0800)
- Fixes #363

ansible/templates/nginx.conf
server/src/main.rs
ui/src/index.tsx
ui/src/utils.ts

index c8afcf4bde932ac3baa368c496710d271c4efb32..a484594ed3978b7c2f9804dee27476f681211f50 100644 (file)
@@ -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;
 }
index cdcd7a65673dacd240e773907f802dd9f3c106fa..98ce8e3fd4d2def5e4c8727b50f9f608dfee5e38 100644 (file)
@@ -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()
index 2e50db882660cf7318f0645e67ab9400bf72b941..41404f4ba6489ea5c93459bd9dc458136b519072 100644 (file)
@@ -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} />
index 1bbda3aa3d35bb879386a11f4546ba8c9488dafb..98645fe390bedb927c85e76b966ddca49796457d 100644 (file)
@@ -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