0

First of all I have tried to click on index.html that served from Actix, it is very fast ever. ... I implement Web Server by GoFiber to serve static files, I use the following code:

package main

import (
    "log"

    "github.com/gofiber/fiber/v2"
)

func main() {
    app := fiber.New()

    app.Static("/", "./public")

    log.Fatal(app.Listen(":8000"))
}

It works properly.

Then I try to implement a Web Server by Rust in Actix, I use the following code:

use actix_files as fs;
use actix_web::{App, HttpServer};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new().service(
            fs::Files::new("/", "./public")
                .show_files_listing()
                .use_last_modified(true),
        )
    })
    .bind("0.0.0.0:8000")?
    .run()
    .await
}

It shows as the following image: enter image description here

How can I change Actix code to serve the whole html files from gatsby deploy automatically like GoFiber? When I click index.html, it works very well and I feel that it blazingly fast more than any other Web Server Platform that I have used.

Maybe I’m wrong in asking questions. I can find the solution:

use actix_files as fs;
use actix_web::{App, HttpServer};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new().service(
            fs::Files::new("/", "./public")
                .show_files_listing()
                .index_file("index.html")
                .use_last_modified(true),
        )
    })
    .bind("0.0.0.0:8000")?
    .run()
    .await
}
sirisakc
  • 892
  • 2
  • 15
  • 30
  • 1
    Per the linked question: `app.route("/", web::get().to(index))` where `index` (`async fn index(_req: HttpRequest) -> Result`) is an async function which serves the file of your choosing. – E_net4 Sep 12 '22 at 10:10
  • @E_net4thecommentflagger this is what I’m looking for use actix_files as fs; use actix_web::{App, HttpServer}; #[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new().service( fs::Files::new("/", "./public") .show_files_listing() .index_file("index.html") .use_last_modified(true), ) }) .bind("0.0.0.0:8000")? .run() .await } – sirisakc Sep 13 '22 at 23:05

0 Answers0