Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timReynolds/micro-redirect
A redirect function for Zeit's micro
https://github.com/timReynolds/micro-redirect
api javascript micro redirect
Last synced: about 2 months ago
JSON representation
A redirect function for Zeit's micro
- Host: GitHub
- URL: https://github.com/timReynolds/micro-redirect
- Owner: timReynolds
- License: mit
- Created: 2017-03-11T17:14:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T23:00:40.000Z (about 2 years ago)
- Last Synced: 2024-10-23T02:50:15.398Z (3 months ago)
- Topics: api, javascript, micro, redirect
- Language: JavaScript
- Size: 404 KB
- Stars: 13
- Watchers: 2
- Forks: 3
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-micro - micro-redirect - A redirect function for Zeit's micro. (Modules / HTTP Requests)
README
_**Micro Redirect -**_
A redirect function for Zeit's [micro](https://github.com/zeit/micro)
[![Build Status](https://travis-ci.org/timReynolds/micro-redirect.svg?branch=master)](https://travis-ci.org/timreynolds/micro-redirect)
[![Maintainability](https://api.codeclimate.com/v1/badges/0d5e4eb0820d66791e2d/maintainability)](https://codeclimate.com/github/timReynolds/micro-redirect/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/0d5e4eb0820d66791e2d/test_coverage)](https://codeclimate.com/github/timReynolds/micro-redirect/test_coverage)## Usage
Firstly, install it:
```bash
npm install --save micro-redirect
```Then import it like this:
```js
const redirect = require("micro-redirect");
```And use it the same you'd use Zeit's send:
```js
module.exports = async (req, res) => {
const statusCode = 302;
const location = "http://github.com";redirect(res, statusCode, location);
};
```#### API
**`redirect(res, statusCode, location)`**
- `statusCode` is a `Number` with the HTTP redirect code, and must always be supplied.
- `location` is a `String` used to set the res header location, and must always be supplied.