0.7.0 • Published 3 months ago

next-ssr-middleware v0.7.0

Weekly downloads
-
License
LGPL-3.0-or-later
Repository
github
Last release
3 months ago

Next SSR middleware

Koa-like middlewares for Next.js Server Side Rendering

NPM Dependency CI & CD

NPM

Versions

SemVerstatusMobXMobX i18n
>=0.7✅developing>=6.11>=0.5
<0.7❌deprecated>=4 <6.11<0.5

Usage

pages/user/[id].tsx

import {
    JWTProps,
    RouterProps,
    jwtVerifier,
    cache,
    errorLogger,
    router,
    translator
} from 'next-ssr-middleware';

import i18n from '../../model/Translation';
import { User, UserModel } from '../../model/User';

type UserDetailPageProps = User & JWTProps & RouterProps;

export const getServerSideProps = compose<{ id: string }, UserDetailPageProps>(
    jwtVerifier(), // set `JWT_SECRET` in `.env.local` first
    cache(),
    errorLogger,
    router,
    translator(i18n),
    async ({ params }) => {
        const props = await new UserModel().getOne(params!.id);

        return { notFound: !props, props };
    }
);

export default function UserDetailPage({
    jwtPayload,
    route,
    name,
    summary
}: UserDetailPageProps) {
    return (
        <>
            <h1>
                {name} - {route.params!.id}
            </h1>
            <p>{summary}</p>
        </>
    );
}

Cases

  1. https://github.com/idea2app/Next-Bootstrap-ts
0.7.0

3 months ago

0.6.2

4 months ago

0.6.1

6 months ago

0.5.2

7 months ago

0.6.0

6 months ago

0.5.3-rc.0

6 months ago

0.5.1

9 months ago

0.5.0

9 months ago