Skip to content
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

Provide documentation on how to use FastUI with local copies of js/css files #309

Open
jimkring opened this issue May 6, 2024 · 3 comments

Comments

@jimkring
Copy link
Contributor

jimkring commented May 6, 2024

Sometimes it's nice to use FastUI's python integration with local copies of the js/css files:

  • Situations where there is no Internet/CDN connectivity, such as behind a corporate firewall (See It works only with internet #307)
  • When using/testing custom builds of the TypeScript components

Instructions might look something like:

Using Local Copies of the JS/CSS files:

  1. download the js and css files locally (ensure you have the correct version numbers, since these links are just examples):
  1. Place index.js and index.css in a folder under your fastapi/flask project where you serve static files, for example inside a static/assets folder.

  2. Configure fastapi and fastui as something like the following. Note that the key is to set the fastui._PREBUILT_CDN_URL variable that fastui uses for defining the location of the JS/CSS files, when generating the HTML pages.

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
import fastui

app = FastAPI()

# make sure you have a folder named 'static' in your project and put the css and js files inside a subfolder called 'assets'
app.mount("/static", StaticFiles(directory="static"), name="static")

# configure fastui to use these local css and js files instead of the ones on the CDN
fastui._PREBUILT_CDN_URL = f'/static/assets'

...

@hasansezertasan
Copy link

I believe the static assets could go in the python package since the NPM version and Python version has different version tags.

I believe it'll be harder to manage NPM version from Python side.

So I propose including assets inside the python dist like Flask Admin which includes bootstrap, select2, etc.

@jimkring
Copy link
Contributor Author

jimkring commented May 7, 2024

@hasansezertasan yes, I was thinking the same thing. the python package should work "out of the box" and include the assets inside the python dist. I guess that there needs to also be some easy way to set up serving these static assets (e.g. from fastapi). It would be nice if this could be part of some magic that the fastui package provides

@hasansezertasan
Copy link

hasansezertasan commented May 7, 2024

I guess that there needs to also be some easy way to set up serving these static assets (e.g. from fastapi). It would be nice if this could be part of some magic that the fastui package provides

I don't think the "easy way to set up serving assets from FastAPI (or Flask or anything else)" is a great idea.

When you install the FastUI Python dist that contains assets, it should be really easy to set it up to serve static files.

When you use FastAPI, you just need to add one extra argument to the StaticFile app. The same goes for Starlette too.

When you use Flask, you just need to plug an extra Blueprint that has 2 or 3 extra parameters passed.

This will keep FastUI more "framework agnostic", without the magic but required assets.

If the author says "That magic sounds good", I recommend a contrib architecture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants