Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abernier/redirect
Connect/Express ?redirect middleware
https://github.com/abernier/redirect
Last synced: about 1 month ago
JSON representation
Connect/Express ?redirect middleware
- Host: GitHub
- URL: https://github.com/abernier/redirect
- Owner: abernier
- Created: 2022-03-06T14:20:04.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-16T09:59:47.000Z (over 2 years ago)
- Last Synced: 2024-11-15T22:28:26.672Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 108 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![ci/cd](https://github.com/abernier/redirect/workflows/ci/cd/badge.svg)](https://github.com/abernier/redirect/actions?query=workflow%3Aci%2Fcd)
[![NPM version](https://img.shields.io/npm/v/@abernier/redirect.svg?style=flat)](https://www.npmjs.com/package/@abernier/redirect)
[![Coverage Status](https://coveralls.io/repos/github/abernier/redirect/badge.svg)](https://coveralls.io/github/abernier/redirect)Connect/Express `?redirect` middleware.
In short, it allows you to override any route/handler `res.redirect('/foo')` with a `?redirect=/bar` querystring param.
# Examples
Setup:
```js
import express from 'express'
import redirect from '@abernier/redirect'const app = express()
app.use(redirect())
```## Basic
```js
app.post('/login', (req, res) => {
// ...res.redirect('/profile') // default redirection
})
```Override the default redirection -> be redirected to `/welcomeback` by adding a `?redirect` querystring param:
```
$ curl -XPOST http://localhost:3000/login?redirect=/welcomeback
```# Publish to NPM
Ready to publish a new version to NPM registry?
## Manually
1. bump the `package.json` version
2. `npm login` if not already
3. `npm publish`If successful, you should want to tag the version:
```shell
$ git add package.json
$ git commit -m "bump version"
$ git tag v1.0.1
$ git push --tags
```## Using [CI/CD](https://github.com/abernier/redirect/actions?query=workflow%3Aci%2Fcd) workflow
Pre-requisite:
1. Generate a new NPM access token on [npmjs.com](https://www.npmjs.com/) (you need a NPM account and be logged-in)
2. Set it as `NPM_TOKEN` secret (in `Settings > Secrets` and as referenced into [`cicd.yml`](https://github.com/abernier/redirect/blob/main/.github/workflows/cicd.yml#L37) file)---
Then, to release a new version on [npm](https://www.npmjs.com/package/redirect):
1. bump the [`package.json` version](https://github.com/abernier/redirect/edit/main/package.json)
2. then, create [a new realese](https://github.com/abernier/redirect/releases/new) and wait for the [ci/cd](https://github.com/abernier/redirect/actions?query=workflow%3Aci%2Fcd) publish it# Links
- Announcement on reddit [r/expressjs](https://www.reddit.com/r/expressjs/comments/t85jzm/connectexpress_redirect_middleware/)