Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] Remove URL shortening #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,50 @@ Build artifacts will be located at `dist` dir.

`Dockerfile` with `nginx.conf` are also provided. Based on [Deployment > Docker (nginx)](https://cli.vuejs.org/guide/deployment.html#docker-nginx).

## Development

### Setting up the `.env` file

You need a file with environment variables to configure Vite for the frontend to properly request either mock data or interact with the backend.

To enable the mocks, write:

```
VITE_FAKE_API_ENABLED=TRUE
```

To interact with the backend, assuming you'll add an API proxy as described below, write:

```
VITE_API_URL=http://localhost:5173/api-proxy
VITE_FAKE_API_ENABLED=FALSE
```

### Connecting to a BCE backend

One may want to see to see how the backend responds in the real time,
but pointing the API endpoint directly in the `VITE_API_URL` property of an `.env` file
would lead to a lot of errors like this one:

Access to fetch at 'http://localhost:port_A/...' from origin 'http://localhost:port_B' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Vite can be configured to proxy the responses.

So, we first return to the `.env` file and configure `VITE_API_URL` property as `http://localhost:5173/api-proxy`, if our `dev` shows the port as 5173.

Then we go to the Vite configuration in `vite.config.js` and add a new part in our `defineConfig` section,
where our `target` points to the host and the port of our BCE backend instance.

```js
server: {
proxy: {
'/api-proxy': {
target: 'http://127.0.0.1:4000',
changeOrigin: true,
secure: false,
ws: false,
rewrite: (path) => '/api/v1' + path.replace(/api-proxy\//, ''),
},
},
},
```
2 changes: 1 addition & 1 deletion src/widgets/latest-transactions/LatestTransactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<BaseHash
:hash="transaction.hash"
type="medium"
type="full"
:link="'/transactions/' + transaction.hash"
/>

Expand Down