Skip to content
프로젝트

소개

Next.js의 getServerSideProps에서 POST 요청, 파일 업로드 및 API 요청을 처리하는 데 필요한 모든 기능을 제공합니다.

웹 및 앱 개발

이 수치를 측정하는 방법

What you can do

  • Handle POST requests in getServerSideProps.
  • Handle file uploads in getServerSideProps.
  • Easily manage headers and cookies.
  • Reuse getServerSideProps as zero-config JSON api.

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

banner

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 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.

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
Stephan Meijer

💻 📖 🤔 🚇 🚧
Gal Schlezinger
Gal Schlezinger

📖
Darius
Darius

💻 ⚠️
Umar Ahmed
Umar Ahmed

💻
HIKARU KOBORI
HIKARU KOBORI

💻
Koichi Kiyokawa
Koichi Kiyokawa

💻 ⚠️
Gorka Cesium
Gorka Cesium

📖
Pandiyan Murugan
Pandiyan Murugan

💻
Jeya Suriya Muthumari
Jeya Suriya Muthumari

🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

관련 프로젝트 살펴보기

불러오는 중…