-
Notifications
You must be signed in to change notification settings - Fork 27
Add a new env var to make the CORS policy permissive #214
Copy link
Copy link
Closed
Labels
Enhancement / Feature RequestSomething NewSomething New
Description
If you want to run the Torrust Index for development with the backend (this repo) and the frontend you have to uncomment a line in the router:
The CorsLayer::permissive() allows the frontend to make requests to the API on a different port.
/// Add all API routes to the router.
#[allow(clippy::needless_pass_by_value)]
pub fn router(app_data: Arc<AppData>) -> Router {
// code-review: should we use plural for the resource prefix: `users`, `categories`, `tags`?
// See: https://stackoverflow.com/questions/6845772/should-i-use-singular-or-plural-name-convention-for-rest-resources
let v1_api_routes = Router::new()
.route("/", get(about_page_handler).with_state(app_data.clone()))
.nest("/user", user::routes::router(app_data.clone()))
.nest("/about", about::routes::router(app_data.clone()))
.nest("/category", category::routes::router(app_data.clone()))
.nest("/tag", tag::routes::router_for_single_resources(app_data.clone()))
.nest("/tags", tag::routes::router_for_multiple_resources(app_data.clone()))
.nest("/settings", settings::routes::router(app_data.clone()))
.nest("/torrent", torrent::routes::router_for_single_resources(app_data.clone()))
.nest("/torrents", torrent::routes::router_for_multiple_resources(app_data.clone()))
.nest("/proxy", proxy::routes::router(app_data.clone()));
Router::new()
.route("/", get(about_page_handler).with_state(app_data))
.nest(&format!("/{API_VERSION_URL_PREFIX}"), v1_api_routes)
// For development purposes only.
//
//.layer(CorsLayer::permissive()) // Uncomment this line and the `use` import.
//
// It allows calling the API on a different port. For example
// API: http://localhost:3000/v1
// @da2ce7 suggested using an env var to avoid changing the code:
TORRUST_IDX_BACK_CORS_PERMISSIVE=true cargo runPlease create a new issue on the frontend after implementing this issue to change the documentation there.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Enhancement / Feature RequestSomething NewSomething New
Type
Projects
Status
No status