Skip to content

Support static assests in handlers #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Angelmmiguel opened this issue Oct 11, 2022 · 4 comments · Fixed by #29
Closed

Support static assests in handlers #7

Angelmmiguel opened this issue Oct 11, 2022 · 4 comments · Fixed by #29
Assignees
Labels
🚀 enhancement New feature or request

Comments

@Angelmmiguel
Copy link
Contributor

Some handlers return HTML code that may require static assets such as JavaScript (client-side) and CSS. Currently, it can be injected in the handler, however is much more convenient to provide a way to set static files.

We can provide this feature using two approaches:

  • Mount generic folders (using WASI) in the handler and provide libraries to manage those files
  • Add a new data.folder configuration property that will serve the files directly using the Rust server

The final approach is still under discussion.

@Angelmmiguel Angelmmiguel added the 🚀 enhancement New feature or request label Oct 11, 2022
@Angelmmiguel Angelmmiguel self-assigned this Nov 14, 2022
@Angelmmiguel
Copy link
Contributor Author

This is a relevant feature for moderm websites. This will allow to build and publish complete websites without having to inject CSS, HTML or JS static code into the wasm compiled binary.

In the end, we will implement this by using a third approach: create a static folder to add static file inside. In this way, we don't need to add any extra configuration as it will work out of the box.

The static prefix won't be added to the files. Based on this structure:

.
├── docs
│   ├── index.js
│   └── static
│       └── intro.jpg
├── index.js
└── static
    └── robots.txt

Wasm Workers Server will init the following routes:

Handlers:
  - /
  - /docs

Static assets:
  - /robots.txt
  - /docs/intro.jpg

This convert static into a reserved word, so you cannot create static folders to host handlers. A static/index.js file will be managed as "static" file and not as a handler.

@Angelmmiguel
Copy link
Contributor Author

Angelmmiguel commented Nov 14, 2022

After revisiting it, we plan to allow only a root static folder for the initial version. Every application is recommended to run on its own wws process. Having multiple static folders inside a project doesn't provide many advantages as they can be also coded as a subfolder in the initial folder:

.
├── docs
│   └── index.js
├── index.js
└── static
    └── docs
       └── intro.jpg
    └── robots.txt

Will be the same as:

.
├── docs
│   ├── index.js
│   └── static
│       └── intro.jpg
├── index.js
└── static
    └── robots.txt

To keep the usage simple, we will focus on the single static folder approach.

@Angelmmiguel
Copy link
Contributor Author

Instead of static, we will use public as it's a common convention in web frameworks like NextJS, Astro, Remix, Ruby on Rails.

@Angelmmiguel
Copy link
Contributor Author

As part of this feature, we should also support static .html files. In this way, we can create static sites and add dynamic features using wasm modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant