This is the backend for the Lnk Shrtnr application. Built with:
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT tokens
- Create a new short URL
- View a short URL details
- Redirect to a short URL
- View all short URLs details
- Delete a short URL
- Login as an admin
- Login as a guest
- Validate that a slug is not in use
- Clone the repository
- Add ignored env file
.devcontainer/devcontainer.env
- Add the following to the file:
TOKEN_SECRET=jwt-signing-secret
- This is only for local development, in production set env var to something more cryptic
- Launch the dev container using vscode
- This will place the env var in the PATH
- Install using npm
npm install
This application expects to find a running mongo database running at 27017. I use a docker container for that but its not picky.
Before running the application, you need to populate the database with an intial user. Creating additional users is supported via an Admin endpoint, but this requires that the request be sent with a valid admin jwt token.
- Add admin user to database manually
- build project
npm run build
- run
node ./docs/hashPassword.js password
- copy output to clipboard and use in next step
- connect to mongo db cli
- add user
use urlShortener
db.users.insertOne({name: 'admin', password: 'copy clipboard', isAdmin: true})
- build project