- API Documentation: Integrated Swagger UI for easy exploration and testing of API endpoints.
- Redirect Management: Create, update, and delete URL redirects with ease.
- Automated Testing: Comprehensive test suites ensure the reliability and stability of the application.
- Continuous Integration: GitHub Actions workflow for linting, testing, and maintaining code quality.
-
Bun: Ensure you have Bun installed. You can install it using the following command:
curl https://bun.sh/install | bash
-
Clone the Repository
git clone /~https://github.com/jakemingolla/url-shortener.git cd url-shortener
-
Install Dependencies
bun install
-
Environment Variables
Create a
.env
file in the root directory and include the necessary environment variables as needed.
Start the server using docker compose
:
bun run start
The server will be listening on http://localhost:3000.
To get logs of the application (or database):
bun run logs:app
bun run logs:postgres
-
Create Redirect
curl \ -X POST \ -H "Content-Type: application/json" \ --data '{ "destination": "http://stackoverflow.com " }' \ http://localhost:3000/api/v1/redirects >> {"id":"b2c3a275-5b2e-44cb-9f0c-aed5a1ca6f4a"}
-
Use Redirect
curl -v localhost:3000/r/b2c3a275-5b2e-44cb-9f0c-aed5a1ca6f4a ... < HTTP/1.1 302 Found < Location: http://stackoverflow.com
-
View Redirect Details
curl \ -X GET \ -H "Content-Type: application/json" \ http://localhost:3000/api/v1/redirects/b2c3a275-5b2e-44cb-9f0c-aed5a1ca6f4a { "id": "b2c3a275-5b2e-44cb-9f0c-aed5a1ca6f4a", "destination": "http://stackoverflow.com ", "hits": 1, "createdAt": "2024-12-30T16:39:41.515Z", "updatedAt": "2024-12-30T16:40:58.357Z", "deletedAt": null }
Access the Swagger UI for interactive API documentation at http://localhost:3000/swagger.
The database seeds add baseline redirects into Postgres for local development and testing.
- Run Seeds
bun run seed:up
- Create Seeds
bun run seed:make <name>
- Reseting Database
bun run reset
Note
You must make sure you have all up-to-date seeds created before running tests.
Run the test suites using Bun:
bun test
Manage your database schema with the provided migration scripts.
-
Run Migrations
bun run migration:up
-
Rollback Migrations
bun run migration:down
-
Create New Migration
bun run migration:make <name>
-
Update
src/db/types.d.ts
This will adjust the TypeScript types to match what's in the current local database
bun run generate-types
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes with clear and descriptive messages.
- Push to your fork and create a pull request.
This project is licensed under the MIT License.
This project was created using bun init
in bun v1.1.42. Bun
is a fast all-in-one JavaScript runtime.