• Stars
    star
    589
  • Rank 75,909 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 3 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

All you need to handle POST requests, file uploads, and api requests, in Next.js getServerSideProps.

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

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.

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):


Stephan Meijer

πŸ’» πŸ“– πŸ€” πŸš‡ 🚧

Gal Schlezinger

πŸ“–

Darius

πŸ’» ⚠️

Umar Ahmed

πŸ’»

HIKARU KOBORI

πŸ’»

Koichi Kiyokawa

πŸ’» ⚠️

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

More Repositories

1

unimported

Find and fix dangling files and unused dependencies in your JavaScript projects.
TypeScript
1,970
star
2

leaflet-geosearch

A geocoding/address-lookup library supporting various api providers.
TypeScript
1,037
star
3

spin-delay

Smart spinner helper for React, to manage the duration of loading states.
JavaScript
182
star
4

redux-define

Define action constants for Redux
JavaScript
174
star
5

where-broke

A CLI utility that helps finding breaking module versions using binary search and automated tests.
JavaScript
92
star
6

jest-partial

A partial matcher for Jest to simplify validation of complex structures.
JavaScript
20
star
7

latodoc

jsDoc3 Theme
JavaScript
19
star
8

graphql-args

A lib that parses the resolver ast, to return the requested object fields and provided params, at any nested level.
JavaScript
12
star
9

blocktober

say STOP to hacktoberfest spammers
JavaScript
11
star
10

paychecker

compare web developer salaries across the planet
TypeScript
5
star
11

issupported.com

Check if your browser is still supported by your favorite websites.
TypeScript
4
star
12

botz

TypeScript
4
star
13

open-api

TypeScript
3
star
14

git-prettier

Run prettier during git clean and smudge stages.
JavaScript
3
star
15

meijer.ws

MDX
2
star
16

cache-key

create stable cache keys from complex objects
TypeScript
2
star
17

smeijer

my ✨special ✨ profile repo
2
star
18

form-data-kit

a lib to parse, stringify, and expand FormData
TypeScript
2
star
19

geoxs-net

GeoXS website
CSS
1
star
20

eslint-config

JavaScript
1
star
21

meteor-prebuild

Compiler plugin to run node script prior to meteor build process
JavaScript
1
star
22

react-emotional

react-emotion extended with some plugins
JavaScript
1
star
23

fetch-addons

A collection of add-ons for the fetch API
TypeScript
1
star
24

something-new

whoei
TypeScript
1
star
25

nexis

CLI utils that help me bootstrap and manage my projects
TypeScript
1
star
26

fetch-repo

fetch a repo from github without git
TypeScript
1
star
27

sme-scripts

JavaScript
1
star
28

tsconfig

Shared TypeScript config for my projects
JavaScript
1
star
29

ts-project

JavaScript
1
star
30

link-workspaces

Link Yarn Workspaces while respecting publishConfig.directory
TypeScript
1
star
31

picoid

Nanoid configured to behave like Meteor Random.id
TypeScript
1
star
32

magicbell-react-nextjs

Next.js template for CodeSandbox Projects
TypeScript
1
star
33

gh-email

retrieve email address by github handle
JavaScript
1
star