GitHub - byliuyang/short: URL shortening service written in Go and React
source link: https://github.com/byliuyang/short
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
Short
Preview
Get s/
Chrome extension
Install it from Chrome Web Store or build it from source
Getting Started
Accessing the source code
git clone https://github.com/byliuyang/short.git
Prerequisites
- Docker v19.03.2
Configure environmental variables
-
Create
.env
file at project root with the following content:DOCKERHUB_USERNAME=local DB_USER=your_db_user DB_PASSWORD=your_db_password DB_NAME=your_db_name RECAPTCHA_SECRET=your_recaptcha_secret GITHUB_CLIENT_ID=your_Github_client_id GITHUB_CLIENT_SECRET= your_Github_client_secret JWT_SECRET= your_JWT_secret WEB_FRONTEND_URL=http://localhost:3000 WEB_PORT=3000 HTTP_API_PORT=80 GRAPHQL_API_PORT=8080
-
Update
DB_USER
,DB_PASSWORD
,DB_NAME
, andJWT_SECRET
with your own configurations.
Create reCAPTCHA account
-
Sign up at ReCAPTCHA with the following configurations:
Field Value LabelShort
reCAPTCHA typereCAPTCHAv3
Domainslocalhost
-
Replace the value of
RECAPTCHA_SECRET
in the.env
file withSECRET KEY
. -
Replace the value of
REACT_APP_RECAPTCHA_SITE_KEY
infrontend/.env.development
file withSITE_KEY
.
Create Github OAuth Application
-
Create a new OAuth app at Github Developers with the following configurations:
Field Value Application NameShort
Homepage URLhttp://localhost
Application descriptionURL shortening service written in Go and React
Authorization callback URLhttp://localhost/oauth/github/sign-in/callback
-
Replace the value of
GITHUB_CLIENT_ID
in the.env
file withClient ID
. -
Replace the value of
GITHUB_CLIENT_SECRET
in the.env
file withClient Secret
.
Generate static assets
Run the following commands at project root:
docker build -t frontend-build -f Dockerfile-build . docker run -v $(pwd)/frontend/build:/app/build frontend-build:latest
Build frontend & backend docker images
docker build -t short-frontend:latest -f frontend/Dockerfile frontend docker build -t short-backend:latest -f backend/Dockerfile backend
Launch App
docker-compose up
Visit http://localhost:3000
Development
Dependencies
- Go v1.13.1
- Node.js v12.12.0
- Yarn v1.19.1
- Postgresql v12.0 ( or use ElephantSQL instead )
Backend
-
Create
.env
underbackend
directory with the following content:DB_HOST=your_db_host DB_PORT=your_db_port DB_USER=your_db_user DB_PASSWORD=your_db_password DB_NAME=your_db_name RECAPTCHA_SECRET=your_recaptcha_secret GITHUB_CLIENT_ID=your_Github_client_id GITHUB_CLIENT_SECRET=your_Github_client_secret JWT_SECRET=your_JWT_secret WEB_FRONTEND_URL=http://localhost:3000
-
Update
DB_HOST
,DB_PORT
,DB_USER
,DB_PASSWORD
,DB_NAME
,RECAPTCHA_SECRET
,GITHUB_CLIENT_ID
,GITHUB_CLIENT_SECRET
,JWT_SECRET
with your own configurations. -
Launch backend server
cd backend ./scripts/dev
Frontend
Remember to update REACT_APP_RECAPTCHA_SITE_KEY
in frontend/.env.development
.
-
Launch frontend server
cd frontend ./scripts/dev
-
Visit http://localhost:3000
System Design
Database Modeling
Deployment
Merging from master
branch to production
branch on Github will automatically
deploy the latest code to the production server. This is called continuous
delivery in the DevOps world.
In the future, when there are enough automated tests, we may migrate to continuous deployment instead.
Tools We Use
- Drone: Continuous integration written in Go
- Sourcegraph: Code search written in Go
- Code Climate: Automated code review
- ElephantSQL: Managed PostgreSQL service.
- QuickDBD: Draw database diagrams by typing.
Contributing
When contributing to this repository, please first discuss the change you wish to make via issues with the owner of this repository before making a change.
Pull Request Process
- Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters.
- You may merge the Pull Request in once you have the sign-off of code owner, or if you do not have permission to do that, you may request the code owner to merge it for you.
Code of Conduct
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members
Discussions
Please join this Slack channel to discuss bugs, dev environment setup, tooling, and coding best practices.
Author
Harry Liu - Initial work - byliuyang
License
This project is maintained under MIT license
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK