Hello everyone, we'll be building on the puppies api. I strongly recommend you look at the previous post for the 🐶🐶🐶 puppies api.
Agenda
✅ Add Swagger Documentation
✅ Deploying to Heroku
Install the swagger docs and the types
Import the modules inside the main.ts file and configure it
Finally, add the ApiProperty
to the Entities.
Let's test our documentation by running yarn start:dev
and visiting localhost:7890/api/docs
Just to be sure our application still works, let's get all the puppies created.
Heroku Deployment
Create an app
Select overview and Configure Add Ons
Search for Heroku postgres
and click
Submit the order form
Click on this to get redirected to the database dashboard
Click on the view credentials
Copy the Database Uri and Head to your ormconfig.js file
orm.config.js
require('dotenv').config();
module.exports = {
url: process.env.DATABASE_URL,
type: 'postgres',
ssl: {
rejectUnauthorized: false,
},
autoLoadEntities: true,
synchronize: true,
logging: true,
entities: ['dist/**/*.entity.js'],
};
Of course, you don't want to hardcode your credentials. We store the Database in the .env
file and imported in here.
Now for the actual deployment, follow these steps
One last thing to do is to add our env to Heroku's env variable
Get the source code here.
Conclusion
I hope this post was helpful. Thanks for reading.
Top comments (0)