refined-ram-93026
04/29/2023, 11:37 AMNo such file or directory (os error 2)
I have added the shuttle_static_folder dependency as in the example, but it was never used in main.rs there.
I'm sure it's me doing something stupid.
I've somewhat extrapolated from the actix-websocket example:
rust
use actix_files::NamedFile;
use actix_web::{ web::{self, ServiceConfig}, Responder };
use shuttle_actix_web::ShuttleActixWeb;
mod api;
mod models;
async fn index() -> impl Responder {
NamedFile::open_async("./static/index.html")
.await
.map_err(|e| actix_web::error::ErrorInternalServerError(e))
}
#[shuttle_runtime::main]
async fn actix_web(
) -> ShuttleActixWeb<impl FnOnce(&mut ServiceConfig) + Send + Clone + 'static> {
let config = move |cfg: &mut ServiceConfig| {
cfg.service(web::resource("/").route(web::get().to(index)));
cfg.service(api::openmeteo::openmeteo);
};
Ok(config.into())
}
Here is the repo: https://github.com/christ-offer/shuttle-actix-apiagreeable-painting-48846
04/29/2023, 11:38 AMshuttle_static_folder lib for static folder support - you can find more about this here https://docs.shuttle.rs/resources/shuttle-static-folderrefined-ram-93026
04/29/2023, 11:40 AMrefined-ram-93026
04/29/2023, 11:40 AMagreeable-painting-48846
04/29/2023, 11:40 AMrefined-ram-93026
04/29/2023, 11:40 AMagreeable-painting-48846
04/29/2023, 11:41 AMfn actix(
#[shuttle_static_folder::StaticFolder] pub: PathBuf
) -> .... etcrefined-ram-93026
04/29/2023, 11:44 AMrust
#[shuttle_runtime::main]
async fn actix_web(
#[shuttle_static_folder::StaticFolder] static_folder: PathBuf,
) -> ShuttleActixWeb<impl FnOnce(&mut ServiceConfig) + Send + Clone + 'static> {
let config = move |cfg: &mut ServiceConfig| {
cfg.service(web::resource("/").route(web::get().to(index)));
cfg.service(api::openmeteo::openmeteo);
};
Ok(config.into())
}agreeable-painting-48846
04/29/2023, 11:44 AMagreeable-painting-48846
04/29/2023, 11:44 AMrefined-ram-93026
04/29/2023, 11:44 AMrefined-ram-93026
04/29/2023, 11:47 AMagreeable-painting-48846
04/29/2023, 11:49 AMrefined-ram-93026
04/29/2023, 11:51 AMrefined-ram-93026
04/29/2023, 11:58 AMhttps://cdn.discordapp.com/attachments/1101834617025200201/1101840035445219368/image.pngâ–¾
agreeable-painting-48846
04/29/2023, 12:00 PMcargo-shuttle are you using at the moment?refined-ram-93026
04/29/2023, 12:00 PMagreeable-painting-48846
04/29/2023, 12:01 PMcargo install cargo-shuttle --force, should work again after thatrefined-ram-93026
04/29/2023, 12:06 PMhttps://cdn.discordapp.com/attachments/1101834617025200201/1101841949545214082/image.pngâ–¾
refined-ram-93026
04/29/2023, 12:07 PMrust
use actix_files::NamedFile;
use actix_web::{ web::{self, ServiceConfig}, Responder };
use shuttle_actix_web::ShuttleActixWeb;
use std::path::PathBuf;
mod api;
mod models;
async fn index() -> impl Responder {
NamedFile::open_async("./static/index.html")
.await
.map_err(|e| actix_web::error::ErrorInternalServerError(e))
}
#[shuttle_runtime::main]
async fn actix_web(
#[shuttle_static_folder::StaticFolder] static_folder: PathBuf,
) -> ShuttleActixWeb<impl FnOnce(&mut ServiceConfig) + Send + Clone + 'static> {
let config = move |cfg: &mut ServiceConfig| {
cfg.service(web::resource("/").route(web::get().to(index)));
cfg.service(api::openmeteo::openmeteo);
};
Ok(config.into())
}agreeable-painting-48846
04/29/2023, 12:08 PMrefined-ram-93026
04/29/2023, 12:08 PMrefined-ram-93026
04/29/2023, 12:08 PMagreeable-painting-48846
04/29/2023, 12:08 PMrefined-ram-93026
04/29/2023, 12:11 PMNo such file or directory (os error 2) hahrefined-ram-93026
04/29/2023, 12:12 PMhttps://cdn.discordapp.com/attachments/1101834617025200201/1101843467195383918/image.pngâ–¾
refined-ram-93026
04/29/2023, 12:13 PMhttps://cdn.discordapp.com/attachments/1101834617025200201/1101843605880066048/image.pngâ–¾
refined-ram-93026
04/29/2023, 12:13 PMagreeable-painting-48846
04/29/2023, 12:13 PMrefined-ram-93026
04/29/2023, 12:15 PMrefined-ram-93026
04/29/2023, 12:15 PMagreeable-painting-48846
04/29/2023, 12:15 PMrefined-ram-93026
04/29/2023, 12:15 PMamedFile::open_async("./static/index.html") so this needs the pathbuf somehow?agreeable-painting-48846
04/29/2023, 12:16 PMagreeable-painting-48846
04/29/2023, 12:16 PMagreeable-painting-48846
04/29/2023, 12:20 PMlet static_folder = static_folder.join("index.html");
let index = NamedFile::open_async(static_folder)
.await
.map_err(|e| actix_web::error::ErrorInternalServerError(e))refined-ram-93026
04/29/2023, 12:27 PMrefined-ram-93026
04/29/2023, 12:27 PM