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

Possibility to render a single route directly to stdout #2466

Open
1 task done
jrutila opened this issue May 24, 2024 · 7 comments
Open
1 task done

Possibility to render a single route directly to stdout #2466

jrutila opened this issue May 24, 2024 · 7 comments
Labels

Comments

@jrutila
Copy link
Contributor

jrutila commented May 24, 2024

Describe the feature

There should be a way to use nitro to generate single pages. One place to run this would be Azure Function that just outputs, using prebuilt nitro files, the desired page output when it is run and then dies out.

This should be possible through the prerender function and a command line tool.

Command line tool would work like this: nitro render /path/to/page and when you want stdout: nitro render --stdout /path/to/page

I have already studied the generateRoute code and will post a PR that will implement the needed options and the cli tool.

Additional information

  • Would you be willing to help implement this feature?
@jrutila
Copy link
Contributor Author

jrutila commented May 24, 2024

This would also trickle down to frameworks like nuxt that could extend its generate command to support single page and stdout renderings.

@jrutila
Copy link
Contributor Author

jrutila commented May 28, 2024

This could be extended so that an output function could be provided with the prerender options. This function would be called with the Buffer and path so that anything could be done with the rendered output. Like, sending to email, saving to cloud storage etc.

@pi0 pi0 added enhancement New feature or request discussion pending and removed pending triage labels Jun 17, 2024
@pi0
Copy link
Member

pi0 commented Jun 17, 2024

This is a nice idea but perhaps something to rethink for the future. (some context: #2467 (comment))

@jrutila
Copy link
Contributor Author

jrutila commented Jun 17, 2024

I would like to work on this feature. You said in the PR: "Nitro has already a CLI preset intended for same thing (standalone output that can render to stdout without depending in nitro builder core) -- PR welcome to improve it". Do you mean the static preset for build command? What would be the desired way to call it from cli?

And, regarding the programmatic API, is the src/core/prerender/prerender.ts file's generateRoute the correct place to implement this (as I did on the PR)? I couldn't find the mentioned prerenderRoute function anywhere. Or am I in wrong branch, now?

@pi0
Copy link
Member

pi0 commented Jun 17, 2024

Do you mean the static preset for build command?
What would be the desired way to call it from cli?

I meant --preset cli (src).

(I guess not working on latest branch needs a simple fix to remove CJS check)

For node variant, ./server/index.mjs [route]. We can add CLI shortcut later but this usage allows to use CLI renderer independent from big Nitro builder package and keep it portable.

And, regarding the programmatic API

Yes we could export it from render.ts however let's not rush into this part as mentioned, we need to first implement smart rebuild.


In summary there are two tracks we can move this forward:

    1. Standalone CLI preset
    1. Selective prerender with smart rebuild

First, requires updates to the current cli preset, is portable and we can work on it today.

Second, requires introduction of smart rebuild and some cleanups in prerender implementation to make sure we can maintain it in the future.

@jrutila
Copy link
Contributor Author

jrutila commented Jun 17, 2024

Alright, now I got the gist of the cli preset. Makes sense. I made a PR for the fix for the preset, now. I will next investigate if it suits my use case.

@jrutila
Copy link
Contributor Author

jrutila commented Jun 17, 2024

That is the PR based on v2

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

No branches or pull requests

2 participants