mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-07 06:28:26 +08:00
feat(connect-history-api-fallback): add typings for connect-history-api-fallback (#16964)
This commit is contained in:
committed by
Mohamed Hegazy
parent
ca6ef96651
commit
a53ef98cd4
@@ -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];
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
34
types/connect-history-api-fallback/index.d.ts
vendored
Normal file
34
types/connect-history-api-fallback/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
22
types/connect-history-api-fallback/tsconfig.json
Normal file
22
types/connect-history-api-fallback/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/connect-history-api-fallback/tslint.json
Normal file
1
types/connect-history-api-fallback/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user