Skip to content

Commit

Permalink
Update fastify to v3 (#86)
Browse files Browse the repository at this point in the history
* update fastify to v3

* add dependabot config

* move CI from Travis to Github actions

* fix type definitions
  • Loading branch information
frikille authored Jun 8, 2020
1 parent 2e4bdce commit 80f57f1
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
update_configs:
- package_manager: "javascript"
directory: "/"
update_schedule: "daily"
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI workflow
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install --ignore-scripts
- name: Test
run: npm test
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# fastify-nextjs

[![Greenkeeper badge](https://badges.greenkeeper.io/fastify/fastify-nextjs.svg)](https://greenkeeper.io/)

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![Build Status](https://travis-ci.org/fastify/fastify-nextjs.svg?branch=master)](https://travis-ci.org/fastify/fastify-nextjs)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) ![CI workflow](https://github.com/fastify/fastify-nextjs/workflows/CI%20workflow/badge.svg)

React server side rendering support for Fastify with [Next](https://github.com/zeit/next.js/#custom-server-and-routing) Framework.

Expand Down Expand Up @@ -44,7 +42,7 @@ If you need to handle yourself the render part, just pass a callback to `next`:
fastify.next('/hello', (app, req, reply) => {
// your code
// `app` is the Next instance
app.render(req.raw, reply.res, '/hello', req.query, {})
app.render(req.raw, reply.raw, '/hello', req.query, {})
})
```
## Acknowledgements
Expand Down
30 changes: 10 additions & 20 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,27 @@
import {
FastifyReply,
FastifyRequest,
HTTPMethod,
Plugin,
RouteSchema,
FastifyPlugin,
FastifySchema,
HTTPMethods
} from 'fastify';
import { IncomingMessage, Server, ServerResponse } from 'http';
import DevServer from 'next/dist/server/next-dev-server';
import { Router } from 'next/router';

declare module 'fastify' {
type FastifyNextCallback = (
app: DevServer,
req: FastifyRequest<any>,
reply: FastifyReply<any>
req: FastifyRequest,
reply: FastifyReply
) => Promise<void>;

interface FastifyInstance<
HttpServer = Server,
HttpRequest = IncomingMessage,
HttpResponse = ServerResponse
> {
interface FastifyInstance {
next(
path: string,
opts?:
| {
method: HTTPMethod;
schema: RouteSchema;
method: HTTPMethods;
schema: FastifySchema;
next: Router;
}
| FastifyNextCallback,
Expand All @@ -37,11 +32,6 @@ declare module 'fastify' {
}
}

declare const fastifyReact: Plugin<
Server,
IncomingMessage,
ServerResponse,
{ [key: string]: any }
>;
declare const fastifyReact: FastifyPlugin<{ [key: string]: any }>;

export = fastifyReact;
export default fastifyReact;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function fastifyNext (fastify, options, next) {
})
.after(() => {
fastify.next('/_next/*',
(app, req, reply) => handleNextRequests(req.req, reply.res)
(app, req, reply) => handleNextRequests(req.raw, reply.raw)
.then(() => {
reply.sent = true
})
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
"next": "^9.3.1"
},
"dependencies": {
"fastify-plugin": "^1.2.1"
"fastify-plugin": "^2.0.0"
},
"devDependencies": {
"@types/node": "^12.12.7",
"@types/react": "^16.9.19",
"@types/react-dom": "^16.9.5",
"cross-env": "^7.0.2",
"fastify": "^2.0.0",
"fastify": "^3.0.0-rc.1",
"next": "^9.3.1",
"react": "^16.12.0",
"react-dom": "^16.6.3",
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test('should support a custom handler', t => {
.register(require('./index'))
.after(() => {
fastify.next('/hello', (app, req, reply) => {
app.render(req.req, reply.res, '/hello', req.query, {})
app.render(req.raw, reply.raw, '/hello', req.query, {})
})
})

Expand Down
4 changes: 2 additions & 2 deletions types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const app = fastify();

app.register(fastifyReact).after(() => {
app.next('/a');

app.next('/*', (nextApp, req, reply) => {
return nextApp
.getRequestHandler()(req.req, reply.res)
.getRequestHandler()(req.raw, reply.raw)
.then(() => {
reply.sent = true;
});
Expand Down

0 comments on commit 80f57f1

Please sign in to comment.