# connect-tryfiles

> nginx try_files style connect middleware: serve local file if exists or proxy to address

Latest version **0.2.1** (published 2014-05-06) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install connect-tryfiles
pnpm add connect-tryfiles
yarn add connect-tryfiles
bun add connect-tryfiles
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2014-05-06 |
| First published | 2014-05-01 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 0.10.x |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Maintainers | gadr90 |

## Links

- npm: https://www.npmjs.com/package/connect-tryfiles
- Repository: https://github.com/gadr/connect-tryfiles
- Issues: https://github.com/gadr/connect-tryfiles/issues
- npm.io page: https://npm.io/package/connect-tryfiles

## Dependencies (5)

- [glob](https://npm.io/package/glob.md) ^3.2.9
- [colors](https://npm.io/package/colors.md) ~0.6.2
- [http-proxy](https://npm.io/package/http-proxy.md) ^1.1.2
- [underscore](https://npm.io/package/underscore.md) ^1.6.0
- [coffee-script](https://npm.io/package/coffee-script.md) 1.7.*

## Recent versions

- 0.2.1 (latest) — 2014-05-06
- 0.1.2 — 2014-05-05
- 0.1.0 — 2014-05-01

## README

connect-tryfiles
================

![Build status](https://travis-ci.org/gadr/connect-tryfiles.png)

nginx try_files style connect middleware: serve local file if exists or proxy to address

### Idea

If a local file is available at the path corresponding to the URL, this middleware will do nothing (giving the chance to some other middleware serve it).
Else, it will proxy the request to the given target.
This way, you can serve local files easily and proxy the rest to your remote server.

### Usage

    connect = require 'connect'
    http = require 'http'
    tryfiles = require 'connect-tryfiles'

    app = connect()
        .use(tryfiles('**', 'http://localhost:9000', {cwd: 'files'}))
        .use(connect.static('./files'))

    server = http.createServer(app).listen(8000)

Assuming there is

- a file at `./files/foo`
- a different server listening at localhost:9000 that returns "world" to any request

Requests to:

- `http://localhost:8000/foo` will retrieve the file at `files/foo`
- `http://localhost:8000/hello` will return "world"

---
_Source: https://npm.io/package/connect-tryfiles · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
