feat(connect-history-api-fallback): add typings for connect-history-api-fallback (#16964)

This commit is contained in:
Douglas Duteil
2017-06-05 20:51:01 +02:00
committed by Mohamed Hegazy
parent ca6ef96651
commit a53ef98cd4
4 changed files with 121 additions and 0 deletions

View File

@@ -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];
}
}
]
});

View File

@@ -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 <https://github.com/douglasduteil>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
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;
}

View File

@@ -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"
]
}

View File

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