Command-line utility to manage your Vercel project redirects. Doubles as a url shortener.
This module is distributed via npm which is bundled with
node. It can be installed as one of your project's devDependencies
and
used via an npm script.
npm install --save-dev vercel-redirects
{
"scripts": {
"shorten": "vercel-redirects"
}
}
You can then then run npm run shorten <destination-url>
.
You can also install and run this globally.
npm install -g vercel-redirects
Or run it through npx
.
npx vercel-redirects https://url.to.redirect.to.com
Use the cli directly from your command line or as an npm script.
Usage: vercel-redirects [options] [command]
Options:
-v, --version Output the current version.
-h, --help display help for command
Commands:
add [options] <destination> [source] Add a new redirect. Short url is created for you if you dont provide a source.
help [command] display help for command
Usage: vercel-redirects add [options] <destination> [source]
Add a new redirect. Short url is created for you if you dont provide a source.
Options:
-c, --status-code <code> HTTP status code. Must be a value between 301-308.
-h, --help display help for command
Note: This is the default command, so it can be left out if you prefer.
vercel-redirects add /destination-url /source-url
vercel-redirects /destination-url /source-url
vercel-redirects -c 302 /destination-url /source-url
vercel-redirects --status-code 302 /destination-url /source-url
vercel-redirects https://codfish.io /source-url
vercel-redirects add /destination-url
vercel-redirects /destination-url
vercel-redirects https://codfish.io
vercel-redirects -c 302 https://codfish.io
vercel-redirects --status-code 302 https://codfish.io
Add configuration in the following ways (in order of precedence):
- A
vercel-redirects
object in yourpackage.json
. - A
.vercelredirectsrc.json
file to the root of your project. - A
.vercelredirectsrc
file to the root of your project.
package.json example:
{
"vercel-redirects": {
"autoPush": true
}
}
.vercelredirectsrc.json and .vercelredirectsrc example:
{
"autoPush": true
}
Variable | Type | Default | Description |
---|---|---|---|
autoPush |
boolean | false |
Automatically commit and push, effectively deploying whenever changes are made. |
I had originally created a URL shortener, codfi.sh
, for a project I built as a part
of a General Assembly course. For a number of reasons, this project was kind of a pain to
maintain for me over the years.
I stumbled upon Kent C. Dodd's
netlify-shortner & his url shortener
app tutorial, and was motivated to create my own and
migrate my short url domain, codfi.sh
to use that instead.
However, I'm a huge fan of Vercel (formally Now) and that's what I personally use for all my
serverless apps. This cli utility was built to help facilitate the creation of redirects & short
urls for Vercel projects, very much in the same vein as netlify-shortener
.
MIT