Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Fastify v3 #125

Merged
merged 9 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

66 changes: 26 additions & 40 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,38 @@
// Definitions by: Jannik <https://github.com/jannikkeye>
// Leo <https://github.com/leomelzer>
/// <reference types="node" />
import * as fastify from 'fastify';
import { Plugin } from "fastify";
import { Server, IncomingMessage, ServerResponse } from "http";
import { Http2SecureServer, Http2Server, Http2ServerRequest, Http2ServerResponse } from "http2";
import * as https from "https";

type HttpServer = Server | Http2Server | Http2SecureServer | https.Server;
type HttpRequest = IncomingMessage | Http2ServerRequest;
type HttpResponse = ServerResponse | Http2ServerResponse;
import { FastifyPlugin, FastifyReply, RawServerBase } from 'fastify'

declare module "fastify" {
interface FastifyReply<HttpResponse> {
sendFile(filename: string, rootPath?: string): FastifyReply<HttpResponse>;
interface FastifyReplyInterface {
sendFile(filename: string, rootPath?: string): FastifyReply;
}
}

declare function fastifyStatic(): fastify.Plugin<
Server,
IncomingMessage,
ServerResponse,
{
root: string;
prefix?: string;
prefixAvoidTrailingSlash?: boolean;
serve?: boolean;
decorateReply?: boolean;
schemaHide?: boolean;
setHeaders?: (...args: any[]) => void;
redirect?: boolean;
wildcard?: boolean | string;
export interface FastifyStaticOptions {
root: string;
prefix?: string;
prefixAvoidTrailingSlash?: boolean;
serve?: boolean;
decorateReply?: boolean;
schemaHide?: boolean;
setHeaders?: (...args: any[]) => void;
redirect?: boolean;
wildcard?: boolean | string;

// Passed on to `send`
acceptRanges?: boolean;
cacheControl?: boolean;
dotfiles?: boolean;
etag?: boolean;
extensions?: string[];
immutable?: boolean;
index?: string[];
lastModified?: boolean;
maxAge?: string | number;
}
>;

declare namespace fastifyStatic {
interface FastifyStaticOptions {}
// Passed on to `send`
acceptRanges?: boolean;
cacheControl?: boolean;
dotfiles?: boolean;
etag?: boolean;
extensions?: string[];
immutable?: boolean;
index?: string[];
lastModified?: boolean;
maxAge?: string | number;
}

export = fastifyStatic;
declare const fastifyStatic: FastifyPlugin<FastifyStaticOptions>

export default fastifyStatic;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,6 @@ function checkRootPathForErrors (fastify, rootPath) {
}

module.exports = fp(fastifyStatic, {
fastify: '>=2.0.0',
fastify: '>=3',
frikille marked this conversation as resolved.
Show resolved Hide resolved
name: 'fastify-static'
})
26 changes: 19 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"scripts": {
"lint": "npm run lint:standard && npm run lint:typescript",
"lint:standard": "standard | snazzy",
"lint:typescript": "standard --parser typescript-eslint-parser --plugin typescript test/types/*.ts",
"lint:typescript": "standardx --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin test/types/*.ts",
"unit": "tap test/*.test.js",
"typescript": "tsc --project ./test/types/tsconfig.json",
"typescript": "tsd",
"test": "npm run lint && npm run unit && npm run typescript",
"example": "node example/server.js",
"coverage": "tap --cov --coverage-report=html test",
Expand All @@ -30,25 +30,37 @@
},
"homepage": "https://github.com/fastify/fastify-static",
"dependencies": {
"fastify-plugin": "^1.6.0",
"fastify-plugin": "^2.0.0",
"glob": "^7.1.4",
"readable-stream": "^3.4.0",
"send": "^0.16.0"
},
"devDependencies": {
"@types/node": "^10.14.9",
"@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0",
"concat-stream": "^2.0.0",
"coveralls": "^3.0.4",
"eslint-plugin-typescript": "^0.14.0",
"fastify": "^2.5.0",
"fastify-compress": "^0.8.1",
"fastify": "^3.0.0-alpha.1",
"fastify-compress": "github:thomheymann/fastify-compress#v3-upgrade",
mcollina marked this conversation as resolved.
Show resolved Hide resolved
"pre-commit": "^1.2.2",
"proxyquire": "^2.1.0",
"simple-get": "^3.0.3",
"snazzy": "^8.0.0",
"standard": "^12.0.0",
"standardx": "^5.0.0",
frikille marked this conversation as resolved.
Show resolved Hide resolved
"tap": "^12.7.0",
"typescript": "^3.5.2",
"typescript-eslint-parser": "^22.0.0"
"tsd": "^0.11.0",
"typescript": "^3.5.2"
},
"tsd": {
"directory": "test/types"
},
"eslintConfig": {
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error"
mcollina marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
15 changes: 4 additions & 11 deletions test/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import * as fastify from 'fastify'
import * as http2 from 'http2'
import * as fastifyStatic from '../..'

console.log(http2.constants.NGHTTP2_NO_ERROR) // fix for http2 is declared but not used
import fastify from 'fastify'
import fastifyStatic, { FastifyStaticOptions } from '../..'

const appWithImplicitHttp = fastify()
const options = {
const options: FastifyStaticOptions = {
acceptRanges: true,
cacheControl: true,
decorateReply: true,
Expand Down Expand Up @@ -35,11 +32,7 @@ appWithImplicitHttp
})
})

const appWithHttp2: fastify.FastifyInstance<
http2.Http2Server,
http2.Http2ServerRequest,
http2.Http2ServerResponse
> = fastify({ http2: true })
const appWithHttp2 = fastify({ http2: true })

appWithHttp2
.register(fastifyStatic, options)
Expand Down
11 changes: 0 additions & 11 deletions test/types/tsconfig.json

This file was deleted.