A simple URL shortener written in Go with a React frontend and Postgres database.
- Shorten urls based on a user defined key
- Alias a key to point to another short url
- Open multiple pages at once by separating keys with a comma
- Alias a key to point to multiple other keys
- Use variables in URLs
- Opensearch integration to provide suggestions directly to browser
- Frontend to view most popular searches and search to find existing links
- Frontend to allow anyone to add and edit links
- Optional authentication using Azure AD or Okta
- Slack
/
command integration - Slackbot integration
The recommended way to test and deploy is using Docker. You will need to run both the go-url app, and the Postgres DB.
Start Postgres
docker run -d -P --name db -e POSTGRES_PASSWORD=password -e POSTGRES_DB=go -e POSTGRES_ADDR=db:5432 postgres:11.3-alpine
Start App
docker run -p 1323:1323 -e HOSTS=localhost -e APP_URI=http://localhost:1323 --link db alexbrazier/go-url
Alteratively use the docker-compose file and run:
docker-compose up
Run Postgres manually or with Docker
docker-compose up postgres
Install node (via nvm), yarn & go
brew install nvm yarn go
nvm install
cd frontend
yarn
yarn start
cd api
dep ensure
POSTGRES_PASS=password HOSTS=localhost APP_URI=http://localhost:3000 go run server.go
Env Var | Required | Default | Example | Description |
---|---|---|---|---|
HOSTS |
yes | go.domain.com,go2.domain.com | List of comma separated hosts that the server will be able to be accessed from | |
BLOCKED_HOSTS |
go.domain.com,go2.domain.com | List of hosts you want to block from being linked - HOSTS are already included to stop recursive calls | ||
APP_URI |
yes | https://go.domain.com | Default URI of app - used to link back to app | |
PORT |
1323 | Port the app will run on | ||
DEBUG |
false | Enable more logging | ||
JSON_LOGS |
false | Use JSON logs where possible | ||
POSTGRES_ADDR |
localhost:5432 | Postgres db address | ||
POSTGRES_DATABASE |
go | Postgres db name | ||
POSTGRES_USER |
postgres | Postgres user | ||
POSTGRES_PASS |
password | Postgres password | ||
SLACK_TOKEN |
xoxb-xxxxxxxxx-xxxxxxxx-xxxx | Slack OAuth token to enable slackbot | ||
SENTRY_API_DSN |
Sentry DSN for go API | |||
SENTRY_FRONTEND_DSN |
Sentry DSN for react frontend | |||
SLACK_SIGNING_SECRET |
xxxxxxxxxxx | Slack signing secret to enable Slack /go command |
||
SLACK_TEAM_ID |
Txxxxxxxx | Slack team id to restrict slash command responses to single team | ||
ENABLE_AUTH |
false | Enable Azure auth or not - if enabled, all other fields must be filled in | ||
AUTH_EXPIRY_SECONDS |
2592000 | Auth cookie expiry (default 30 days) | ||
SECURE_COOKIES |
true | Use secure https only cookies | ||
AD_TENANT_ID |
Azure AD tenant ID | |||
AD_CLIENT_ID |
Azure AD client ID | |||
AD_CLIENT_SECRET |
Azure AD client secret | |||
OKTA_CLIENT_ID |
Okta client ID | |||
OKTA_CLIENT_SECRET |
Okta client secret | |||
OKTA_ISSUER |
https://dev-123.oktapreview.com/oauth2/default | Okta issuer url | ||
SESSION_TOKEN |
Secret session token to store the user sessions | |||
ALLOWED_IPS |
110.1.10.2,1.1.22.0/24 | IP addresses or CIDRs that are always allowed access, even with auth enabled | ||
ALLOW_FORWARDED_FOR |
false | Retrieve origin IP from X-Forwarded-For header. Only enable if source is trusted, e.g. via Cloudfront | ||
FORWARDED_FOR_TRUST_LEVEL |
1 | Number of levels to trust X-Forwarded-For header - should map to number of proxies used |
When enabled, the Slackbot will be running on every node in a load balanced system. Either disable load balancing, or run a separate instance just for the Slackbot.