From 80f57f16523b4768d7e529c4c7c67c74c9641b71 Mon Sep 17 00:00:00 2001 From: Peter Balazs Date: Mon, 8 Jun 2020 22:09:57 +0200 Subject: [PATCH] Update fastify to v3 (#86) * update fastify to v3 * add dependabot config * move CI from Travis to Github actions * fix type definitions --- .dependabot/config.yml | 5 +++++ .github/workflows/ci.yml | 18 ++++++++++++++++++ .travis.yml | 12 ------------ README.md | 6 ++---- index.d.ts | 30 ++++++++++-------------------- index.js | 2 +- package.json | 4 ++-- test.js | 2 +- types.test.ts | 4 ++-- 9 files changed, 41 insertions(+), 42 deletions(-) create mode 100644 .dependabot/config.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.dependabot/config.yml b/.dependabot/config.yml new file mode 100644 index 00000000..cae63e34 --- /dev/null +++ b/.dependabot/config.yml @@ -0,0 +1,5 @@ +version: 1 +update_configs: + - package_manager: "javascript" + directory: "/" + update_schedule: "daily" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..38ce605a --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index cf07e222..00000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: node_js - -node_js: - - "13" - - "12" - - "11" - - "10" - -notifications: - email: - on_success: never - on_failure: always diff --git a/README.md b/README.md index 4424c51c..94f91db1 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/index.d.ts b/index.d.ts index c87dc843..5d8a1aa9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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, - reply: FastifyReply + req: FastifyRequest, + reply: FastifyReply ) => Promise; - 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, @@ -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; diff --git a/index.js b/index.js index 0d73bde1..713d50d7 100644 --- a/index.js +++ b/index.js @@ -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 }) diff --git a/package.json b/package.json index dda87af4..2526ba45 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test.js b/test.js index e9be8c41..6c568701 100644 --- a/test.js +++ b/test.js @@ -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, {}) }) }) diff --git a/types.test.ts b/types.test.ts index 4130e90c..8834ce03 100644 --- a/types.test.ts +++ b/types.test.ts @@ -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; });