# slash-connecter

> Trailing slash redirect middleware for Connect and Express.js

Latest version **1.0.0** (published 2024-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install slash-connecter
pnpm add slash-connecter
yarn add slash-connecter
bun add slash-connecter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-03-11 |
| First published | 2024-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 4 |
| Unpacked size | 13 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Segi segidcrawfordmelvin9730@outlook.com |
| Maintainers | sofasoddevs |
| Keywords | trailing, slash, connect, middleware, express |

## Links

- npm: https://www.npmjs.com/package/slash-connecter
- Repository: https://github.com/SofaModDevs/slash-connecter
- Homepage: https://github.com/SofaModDevs/slash-connecter#readme
- Issues: https://github.com/SofaModDevs/slash-connecter.git
- npm.io page: https://npm.io/package/slash-connecter

## Dependencies (4)

- [city-near-me](https://npm.io/package/city-near-me.md) ^1.0.0
- [remove-value-js](https://npm.io/package/remove-value-js.md) ^1.0.1
- [markdown-expands-tab](https://npm.io/package/markdown-expands-tab.md) ^1.2.0
- [add-local-binaries-path](https://npm.io/package/add-local-binaries-path.md) ^1.0.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2024-03-11

## README

# slash-connecter

===============

Trailing slash redirect middleware for Connect and Express.js. Useful for creating canonical urls in your Node.js applications.

## Installation

```
$ npm install slash-connecter
```

## Usage

```javascript
var connect = require("connect")
  , slashes = require("slash-connecter");

connect() // or express()
  .use(connect.static())
  .use(slashes()) // must come after static middleware!
  .listen(3000);
```

Alternatively, you can pass `false` as the first argument to `.slashes()` in order to remove trailing slashes instead of appending them:

```javascript
.use(slashes(false));
```

## Additional settings

You can also pass a second argument with an options object. For example, if an application is behind a reverse proxy server that removes part of the URL (a base_path) before proxying to the application, then the `base` can be specified with an option:

```javascript
.use(slashes(true, { base: "/blog" })); // prepends a base url to the redirect
```

By default, all redirects are using the 301 Moved Permanently header. You can change this behavior by passing in the optional `code` option:

```javascript
.use(slashes(true, { code: 302 })); // 302 Temporary redirects
```

You can also set additional headers to the redirect response with the `headers` option:

```javascript
.use(slashes(true, { headers: { "Cache-Control": "public" } }));
```

## Notes

1. Only GET, HEAD, and OPTIONS requests will be redirected (to avoid losing POST/PUT data)
2. This middleware will append or remove a trailing slash to all request urls. This includes filenames (/app.css => /app.css/), so it may break your static files. Make sure to `.use()` this middleware only after the `connect.static()` middleware.

## LICENSE

MIT

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