Skip to content

Conversation

josecelano
Copy link
Member

This is a rework of PR #68

Static Web Server has published a library, so we can directly use the library now.

I've just copied their main.rs file. It works.

Now we can publish a crate, but that crate is a generic static web server. What we want is a web server that contains the corresponding frontend app dist, don't we?

I think there are two ways of embedding the dist so the server version contains the corresponding frontend app dist:

  • Including the dist dir in the cargo package (what I'm doing right now, but I do not know yet how to use the embedded files).
  • Including the dist dir in the executable.

Questions

This crate will be generic, meaning you have to provide the frontend app artefact to serve.

If we embed the dist folder into the binary, we have to find out how to serve it.
I found this project https://github.com/pyrossh/rust-embed, but I'm not sure if that can work for us. I suppose we should write the files the first time the app is executed and then serve them from the disk. I don't think "Static Web Serve" allows you to serve directly from memory.

If we embed the dist folder in the package, we could try to use those files when the bin is installed with cargo install because it builds the app. Maybe with a custom build script.

With this version, we only fulfil goals 1 and 3 (see below), but not 2 (deployment), you need to combine both the server and the dist. If you install the app from sources, it's OK because you can build it, but you can not use directly the binary.

Next

  • Should I try to find out how to embed the dist (5MB) in the binary and use that distribution when you run it in production?
  • I also have to find out how to setup HTTPs certificates (that should be easy, It seems "Static Web Server" support TLS)
  • Support for auto-renewing Let's Encrypt certificates?
  • We could keep it this way and use the docker if we want to pack the server and the dist together. But I would like to be able to run the whole solution only with Rust (tracker+index-backend+index-frontend).

Goals

From the previous PR.

  1. Provide a default embed production-ready static web server so that you do not need any other external dependency to run the index. You only need Rust.
  2. Provide an easy setup/deployment.
  3. Create a Rust package for the index frontend to control dependencies between the main three packages: tracker, backend and frontend. Tracker and backend use Rust, and you new to manually check which version you use to be sure they are compatible.

It will be used to serve the frontend app with Rust.
The purposes of having a static web server in Rust are:

- To provide a default embed production-ready static web server so that you do not need any other external dependency to run the "Index Frontend" in production. You only need Rust.
- To provide an easy setup/deployment.
- To create a Rust package for the index frontend to control dependencies between the main three packages: [Tracker](https://github.com/torrust/torrust-tracker), [Index-Backend](https://github.com/torrust/torrust-index-backend) and [Index-Frontend](https://github.com/torrust/torrust-index-frontend). The Tracker and Index-Backend use Rust, and you need to manually check which version you use to be sure they are compatible.
@da2ce7
Copy link
Contributor

da2ce7 commented Apr 15, 2023

I think that the create: https://crates.io/crates/npm_rs could be interesting for our purposes.

@da2ce7 da2ce7 added the Needs Rebase Base Branch has Incompatibilities label Jul 3, 2023
@josecelano
Copy link
Member Author

Relates to #182

You cannot change the API base URL at runtime if you are deploying the app using a static version. In that case, you need to rebuild the app.

@da2ce7
Copy link
Contributor

da2ce7 commented Jul 17, 2023

Maybe we should accept the API base URL as a environmental variable: TORRUST_BACKEND_API_URI or something?

@josecelano
Copy link
Member Author

josecelano commented Jul 17, 2023

Maybe we should accept the API base URL as a environmental variable: TORRUST_BACKEND_API_URI or something?

There is an env var, see #182. The problem is only when you want to build the app as a static site.

@josecelano josecelano closed this by deleting the head repository Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Rebase Base Branch has Incompatibilities

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants