smeijer/next-runtime
关于
在 Next.js 的 getServerSideProps 中处理 POST 请求、文件上传和 API 请求所需的一切。
网站与应用开发可以做什么
- Handle POST requests in getServerSideProps.
- Handle file uploads in getServerSideProps.
- Easily manage headers and cookies.
- Reuse getServerSideProps as zero-config JSON api.
实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文
All you need to handle POST requests and file uploads in getServerSideProps.
Documentation
All documentation and guides can be found at next-runtime.meijer.works.
Features
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
getServerSidePropsas 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.
import fs from 'fs';
import { handle, json } from 'next-runtime';
export const getServerSideProps = handle({
async upload({ file, stream }) {
stream.pipe(fs.createWriteStream(`/uploads/${file.name}`));
},
async get({ params, query }) {
return json({ name: 'Stephan Meijer' });
},
async post({ req: { body } }) {
return json({ message: 'Thanks for your submission!' });
},
});
export default function Home({ name, message }) {
if (message) {
return <p>{message}</p>;
}
return (
<form method="post" encType="multipart/form-data">
<input name="name" defaultValue={name} />
<input type="file" name="file" />
<button type="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.
Contributors
Thanks goes to these wonderful people (emoji key):
Stephan Meijer 💻 📖 🤔 🚇 🚧 |
Gal Schlezinger 📖 |
Darius 💻 ⚠️ |
Umar Ahmed 💻 |
HIKARU KOBORI 💻 |
Koichi Kiyokawa 💻 ⚠️ |
Gorka Cesium 📖 |
Pandiyan Murugan 💻 |
Jeya Suriya Muthumari 🚧 |
This project follows the all-contributors specification. Contributions of any kind welcome!
探索相关项目
加载中…