next-ssr-middleware
v0.8.9
Published
Koa-like middlewares for Next.js Server Side Rendering
Downloads
147
Readme
Next SSR middleware
Koa-like middlewares for Next.js Server Side Rendering
Versions
| SemVer | status | MobX | MobX i18n |
| :-----: | :----------: | :---------: | :------------: |
| >=0.7
| ✅developing | >=6.11
| >=0.5
|
| <0.7
| ❌deprecated | >=4 <6.11
| <0.5
|
Middlewares
- Router
- Error logger
- JWT verifier
- Props cache
- i18n loader
- OAuth 2 signer (with common providers)
- GitHub
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
- https://github.com/idea2app/Next-Bootstrap-ts
- https://github.com/kaiyuanshe/kaiyuanshe.github.io
- https://github.com/kaiyuanshe/OpenHackathon-Web
- https://github.com/kaiyuanshe/OSS-toolbox