Configuration
Our application fully works now.
Anyway, a good application should have a configuration object to hold the application settings. In this guide, we will learn how to define a configuration object and how to use it in our application.
Application configuration
We have to define the configuration object that will hold the URL of the quote endpoint.
Let's start by defining the configuration object and the TypeScript type.
Replace the src/index.ts
file content with the following:
We defined a configuration object that holds the URL of the quote endpoint. As the fourth argument, we passed this object to the start
function.
Let's see how we can use this configuration object. Replace the src/Main.tsx
file content with the following:
We changed the getRandomQuote
function to receive the baseUrl
as an argument. We used the app.config
object to access the configuration object.
NB: the tests fail because we didn't update the tests to pass the configuration object. We will cover this in the next guide.
Conclusion
Even if the configuration part is not commonly covered in tutorials, it's essential to any application. In this guide, we learned how to define a configuration object and how to use it in our application.