Skip to main content

Fake repository

The Fake repository is a tool that allows developers to run Micro Frontends locally within the Application Host context. With that, it's no longer needed to deploy in staging to test your changes.

How does it work?

The intended workflow to develop Micro Frontends is to run yarn start in the directory of your Micro Frontend. This will run your project on port 3001 with hot reload enabled. Basically, it is running a create react app under the hood. We call this development way as FrontHub stand alone.

Now, suppose you want to test your changes locally, inside the Application Host.

First, in your Micro Frontend root directory, often in the packages/micro-frontend-folder, you need to run the following command:

yarn fake repository

The FrontHub will start a Micro Frontend instance ready to be consumed for any other Application Host, often on port 3001 if it is free. You can also customize the port number, passing in the cli:

yarn fake repository -p 3002

Photo of terminal displaying the Fake repository server up and running

info

Whenever new changes are made to the Micro Frontend code, it will be necessary to stop the Fake repository and then run it agian.

Finally, in Application Host, you need to change the value of the repository property in the FrontHub configuration call to the address indicated in the above command output:

<script>
fronthub('configure', {
repository: 'http://localhost:3002',
})
</script>

See how to integrate the Fake repository with RD Station Marketing.

info

Consider using environment variables in the Application Host to set the value of the repository property.

Using with different environments

By default, fake repository will run as production, but it is possible to run it with different environments.

-stg or –straging: to run as staging

yarn fake repository -stg

-d or –development: to run as development

yarn fake repository -d

What is the difference

This is used to allow Fronthub to consume various .env files, access environments docs for more information, and to use various client endpoints.

Using Fake repository in old projects

To use the Fake repository in projects that were created without the FrontHub CLI, or by FrontHub CLI versions lower than 5, you must include the package @resultadosdigitais/front-hub-cli as a dependency of your project and add to package.json the following entry in the "scripts" attribute:

{
"scripts": {
"fake": "front-hub fake"
}
}