diff --git a/types/fastify-static/fastify-static-tests.ts b/types/fastify-static/fastify-static-tests.ts new file mode 100644 index 0000000000..630fc0ef52 --- /dev/null +++ b/types/fastify-static/fastify-static-tests.ts @@ -0,0 +1,16 @@ +import path = require("path"); +import fastify = require("fastify"); +import fastifyStatic = require("fastify-static"); + +const app = fastify(); + +app.register(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 +}); diff --git a/types/fastify-static/index.d.ts b/types/fastify-static/index.d.ts new file mode 100644 index 0000000000..bfd2435bd6 --- /dev/null +++ b/types/fastify-static/index.d.ts @@ -0,0 +1,40 @@ +// Type definitions for fastify-static 0.14 +// Project: https://github.com/fastify/fastify-static +// Definitions by: Leonhard Melzer +// 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 { + sendFile(filename: string): FastifyReply; + } +} + +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; diff --git a/types/fastify-static/package.json b/types/fastify-static/package.json new file mode 100644 index 0000000000..e8c68ab969 --- /dev/null +++ b/types/fastify-static/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "fastify": "^1.11.2" + } +} diff --git a/types/fastify-static/tsconfig.json b/types/fastify-static/tsconfig.json new file mode 100644 index 0000000000..bdfa7d40c6 --- /dev/null +++ b/types/fastify-static/tsconfig.json @@ -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"] +} diff --git a/types/fastify-static/tslint.json b/types/fastify-static/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/fastify-static/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }