-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Generate sitemap for dynamic deploy url #4923
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty cool, a couple of suggestions,
- the implementation should be outside of app.py and imported from there
- consider generating the sitemap.xml during compile time and place the resulting file in the frontend assets to avoid having to generate xml for each request, when the content is unlikely to have changed.
There is a plan to introduce dynamic sitemaps, f.e. for a blog. This would require to implement 2 different approaches, one for static sitemap and one for dynamic sitemap. We could f.e. try to auto-detect if dynamic features are used or add a config option for that. |
@masenf running it before compile time would mean that backend must replace deploy url if its different from the ones in sitemap. I would think the better approach would be to run the sitemap generation when the app is deployed for the first time on the server. This would allow the same image to be deployed in different servers with unique sitemaps. |
@masenf I have made changes as per your suggestions
|
CodSpeed Performance ReportMerging #4923 will not alter performanceComparing Summary
|
f009734
to
86e46cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good, but when i reflex export
, it looks like .web/_static
directory is deleted. it's probably better to write into .web/public
.
if possible, this should remove the next-sitemap
dependency as we're not using it anymore.
run pre-commit
and address unit test failures
When you run reflex export, the _static folder is not created. The reason being i commented the next-sitemap generation. The deployment will create the _static folder. |
9edc8b4
to
33610bd
Compare
@masenf I have fixed the errors. Do you agree to my reasoning related to not needed to write to PUBLIC folder? Like, when we build our web app, the static folder is not created. when we start the app, sitemaps are generated and written in the static folder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to work:
reflex run
http://localhost:8000/sitemap.xml -- no pages are listed
The following commands simulate a common production-like workflow and it also doesn't work with the sitemap logic as written:
reflex init
reflex export --frontend-only --no-zip
mv .web/_static /tmp/srv && (cd /tmp/srv && python3.12 -m http.server 3000) &
reflex run --backend-only
- http://localhost:3000/sitemap.xml is a 404
- http://localhost:8000/sitemap.xml does not list any pages
In a backend-only deployment, the page routes are not compiled, so app._pages
is empty. That's why it doesn't really make sense to have get_pages
. If you want to get all of the routes that would be compiled, you need to use app._unevaluated_pages
.
I also still think it makes sense to export a static sitemap.xml with the frontend, so that it can be served even when the backend is down. If you also need to dynamically regenerate the sitemap.xml when the backend is running, i suppose that's okay too, but i still don't see the advantage of that personally.
@masenf Yeahh I see the mistake in the approach. I will change the approach then. |
5f924d1
to
e578223
Compare
@masenf I have made the required changes, and tested it with reflex run. It works now. |
@masenf @benedikt-bartscher, Does it fulfil all the requirements? or is there something else that needs to be added? |
All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features:
After these steps, you're ready to open a pull request.