diff --git a/types/connect-history-api-fallback/connect-history-api-fallback-tests.ts b/types/connect-history-api-fallback/connect-history-api-fallback-tests.ts new file mode 100644 index 0000000000..382e436366 --- /dev/null +++ b/types/connect-history-api-fallback/connect-history-api-fallback-tests.ts @@ -0,0 +1,64 @@ +import * as historyApiFallback from 'connect-history-api-fallback'; + +import * as express from "express"; + +const app = express(); +app.use(historyApiFallback()); + +historyApiFallback({ + verbose: true +}); + +historyApiFallback({ + logger: console.log.bind(console) +}); + +historyApiFallback({ + rewrites: [ + { from: /\/soccer/, to: '/soccer.html' } + ] +}); + +historyApiFallback({ + index: 'default.html' +}); + +historyApiFallback({ + htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'] +}); + +historyApiFallback({ + rewrites: [ + { + from: /^\/libs\/(.*)$/, + to(context) { + return './bower_components' + context.parsedUrl.pathname; + } + } + ] +}); + +historyApiFallback({ + rewrites: [ + { + from: /\/app\/login/, + to: function onMatch(ctx) { + if (ctx.parsedUrl.path && ctx.parsedUrl.path.indexOf('.js')) { + return ctx.parsedUrl.href || ''; + } + return '/app/login/index.html'; + } + } + ] +}); + +historyApiFallback({ + rewrites: [ + { + from: /^\/libs\/(.*)$/, + to(context) { + return '/' + context.match[2] + '/' + context.match[3]; + } + } + ] +}); diff --git a/types/connect-history-api-fallback/index.d.ts b/types/connect-history-api-fallback/index.d.ts new file mode 100644 index 0000000000..9cd77ac174 --- /dev/null +++ b/types/connect-history-api-fallback/index.d.ts @@ -0,0 +1,34 @@ +// Type definitions for connect-history-api-fallback 1.3 +// Project: https://github.com/bripkens/connect-history-api-fallback#readme +// Definitions by: Douglas Duteil +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { Url } from 'url'; + +import * as core from "express-serve-static-core"; + +declare function historyApiFallback(options?: Options): core.RequestHandler; +declare namespace historyApiFallback {} +export = historyApiFallback; + +interface Options { + disableDotRule?: true; + htmlAcceptHeaders?: string[]; + index?: string; + logger?: typeof console.log; + rewrites?: Rewrite[]; + verbose?: boolean; +} + +interface Context { + match: RegExpMatchArray; + parsedUrl: Url; +} +type RewriteTo = (context: Context) => string; + +interface Rewrite { + from: RegExp; + to: string | RegExp | RewriteTo; +} diff --git a/types/connect-history-api-fallback/tsconfig.json b/types/connect-history-api-fallback/tsconfig.json new file mode 100644 index 0000000000..124c7dc340 --- /dev/null +++ b/types/connect-history-api-fallback/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "connect-history-api-fallback-tests.ts" + ] +} diff --git a/types/connect-history-api-fallback/tslint.json b/types/connect-history-api-fallback/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/connect-history-api-fallback/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }