Skip to content

Commit

Permalink
Publish a new version to resolve the [issue](easy-team/webpack-tool#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl@126.com committed Apr 3, 2019
1 parent 0dbb433 commit 82277cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 87 deletions.
90 changes: 5 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,11 @@
<h1 align="center">koa-history-api-fallback</h1>
<p align="center">Koa implementation of [connect-history-api-fallback](https://github.com/bripkens/connect-history-api-fallback)
## @easy-team/koa-history-api-fallback

[![NPM](https://nodei.co/npm/koa-history-api-fallback.png?downloads=true&downloadRank=true)](https://nodei.co/npm/koa-history-api-fallback/)
Fork [koa-history-api-fallback](https://github.com/dalhorinek/koa-history-api-fallback) and Publish a new version to resolve the [issue](https://github.com/easy-team/webpack-tool/issues/4)

## Introduction
## Install

This is simple rewrite of [connect-history-api-fallback](https://github.com/bripkens/connect-history-api-fallback)
npm install @easy-team/koa-history-api-fallback --save-dev

## Usage

The middleware is available through NPM and can easily be added.

```
npm install --save koa-history-api-fallback
```

Import the library

```javascript
var historyApiFallback = require('koa-history-api-fallback');

var app = koa();

app.use(historyApiFallback());
```

## Options
You can optionally pass options to the library when obtaining the middleware

```javascript
var middleware = historyApiFallback({});
```

### index
Override the index (default `/index.html`)

```javascript
historyApiFallback({
index: '/default.html'
});
```

### rewrites
Override the index when the request url matches a regex pattern. You can either rewrite to a static string or use a function to transform the incoming request.

The following will rewrite a request that matches the `/\/soccer/` pattern to `/soccer.html`.
```javascript
historyApiFallback({
rewrites: [
{ from: /\/soccer/, to: '/soccer.html'}
]
});
```

Alternatively functions can be used to have more control over the rewrite process. For instance, the following listing shows how requests to `/libs/jquery/jquery.1.12.0.min.js` and the like can be routed to `./bower_components/libs/jquery/jquery.1.12.0.min.js`. You can also make use of this if you have an API version in the URL path.
```javascript
historyApiFallback({
rewrites: [
{
from: /^\/libs\/.*$/,
to: function(context) {
return '/bower_components' + context.parsedUrl.pathname;
}
}
]
});
```

The function will always be called with a context object that has the following properties:

- **parsedUrl**: Information about the URL as provided by the [URL module's](https://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost) `url.parse`.
- **match**: An Array of matched results as provided by `String.match(...)`.


### verbose
This middleware does not log any information by default. If you wish to activate logging, then you can do so via the `verbose` option or by specifying a logger function.

```javascript
historyApiFallback({
verbose: true
});
```

Alternatively use your own logger

```javascript
historyApiFallback({
logger: console.log.bind(console)
});
```
see [koa-history-api-fallback](https://github.com/dalhorinek/koa-history-api-fallback)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koa-history-api-fallback",
"version": "0.1.2",
"name": "@easy-team/koa-history-api-fallback",
"version": "1.0.0",
"description": "Provides a fallback for non-existing directories so that the HTML 5 history API can be used for Koa.",
"keyswords": [
"koa",
Expand Down

0 comments on commit 82277cb

Please sign in to comment.