feat: Add fastify-static typings

This commit is contained in:
Leonhard Melzer
2018-09-27 14:54:17 +02:00
parent 3ee3f99b00
commit d79bda3a35
5 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
import path = require("path");
import fastify = require("fastify");
import fastifyStatic = require("fastify-static");
const app = fastify();
app.register<fastifyStatic.FastifyStaticOptions>(fastifyStatic, {
root: path.join(__dirname, "public"),
prefix: "/public/", // optional: default '/'
immutable: true,
maxAge: 42
});
app.get("/another/path", (req, reply) => {
reply.sendFile("myHtml.html"); // serving path.join(__dirname, 'public', 'myHtml.html') directly
});

40
types/fastify-static/index.d.ts vendored Normal file
View File

@@ -0,0 +1,40 @@
// Type definitions for fastify-static 0.14
// Project: https://github.com/fastify/fastify-static
// Definitions by: Leonhard Melzer <https://github.com/leomelzer>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
import { Server, IncomingMessage, ServerResponse } from "http";
import * as fastify from "fastify";
declare module "fastify" {
interface FastifyReply<HttpResponse> {
sendFile(filename: string): FastifyReply<HttpResponse>;
}
}
declare function fastifyStatic(): void;
declare namespace fastifyStatic {
interface FastifyStaticOptions {
root: string;
prefix?: string;
serve?: boolean;
decorateReply?: boolean;
schemaHide?: boolean;
setHeaders?: () => void;
// 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;

View File

@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"fastify": "^1.11.2"
}
}

View File

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "fastify-static-tests.ts"]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }