You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
next-runtime aims to move more logic to the "runtime part" of your Next.js server, and less static site generation. With proper cache headers, every server is an (incremental) static site generator.
To achieve that, we provide you a convenient API to:
Handle POST requests in getServerSideProps.
Handle file uploads in getServerSideProps.
Easily manage headers and cookies.
Reuse getServerSideProps as zero-config JSON api.
Usage
In case you're not the documentation type of person, here's a quick example to get you up and running. Please consult the docs if this leaves you with questions.
importfsfrom'fs';import{handle,json}from'next-runtime';exportconstgetServerSideProps=handle({asyncupload({ file, stream }){stream.pipe(fs.createWriteStream(`/uploads/${file.name}`));},asyncget({ params, query }){returnjson({name: 'Stephan Meijer'});},asyncpost({req: { body }}){returnjson({message: 'Thanks for your submission!'});},});exportdefaultfunctionHome({ name, message }){if(message){return<p>{message}</p>;}return(<formmethod="post"encType="multipart/form-data"><inputname="name"defaultValue={name}/><inputtype="file"name="file"/><buttontype="submit">submit</button></form>);}
Sponsor
Are you, or your employer, a satisfied user of this, or any of my other projects. Then please consider sponsoring my work so I can dedicate more time to maintaining this kind of projects.
Contributing
Please check contributing.md. It contains info about the structure of this repo
to help you get up and running.
Contributors
Thanks goes to these wonderful people (emoji key):