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

feat(dev-server): configure request proxy for dev-server #1299

Merged
merged 7 commits into from
Jul 10, 2024
Merged
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
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,24 @@ Development environment supports hot reload with Webpack's [Hot Module Replaceme

### With Cryostat

First, launch a [`Cryostat`](https://github.com/cryostatio/cryostat) instance with CORS enabled by setting `CRYOSTAT_CORS_ORIGIN` to `http://localhost:9000`. For example:

First, launch a [`Cryostat`](https://github.com/cryostatio/cryostat) instance:
```bash
$ cd /path/to/cryostat
$ CRYOSTAT_DISABLE_SSL=true CRYOSTAT_CORS_ORIGIN=http://localhost:9000 sh run.sh
$ bash smoketest.bash
```

Then, run:

```bash
# To configure the URL pointing to Cryostat, set CRYOSTAT_PROXY_URL
# By default, CRYOSTAT_PROXY_URL is set to https://localhost:8443
$ yarn start:dev
# or without TLS
$ CRYOSTAT_PROXY_URL=http://localhost:8080 yarn start:dev
```

The dev server will proxy API requests to Cryostat and Grafana.

### Without Cryostat

To quickly preview changes without launching a `Cryostat` instance, run:
Expand Down
8 changes: 3 additions & 5 deletions src/app/Shared/Services/Report.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ export class ReportService {
}
const headers = new Headers();
headers.append('Accept', 'application/json');
let url = recording.reportUrl;
if (!url.startsWith(this.login.authority)) {
url = `${this.login.authority}/${recording.reportUrl}`;
}
return fromFetch(url, {
let url = new URL(recording.reportUrl, document.location.href);

return fromFetch(url.toString(), {
method: 'GET',
mode: 'cors',
credentials: 'include',
Expand Down
15 changes: 14 additions & 1 deletion webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,23 @@ module.exports = merge(common('development'), {
hot: true,
open: true,
port: PORT,
// In preview mode, requests are intercepted with miragejs
proxy: process.env.PREVIEW? undefined: [
{
context: ['/api', '/health', '/grafana'],
target: process.env.CRYOSTAT_PROXY_URL ?? 'https://localhost:8443',
secure: false, // ignore insecure tls
auth: 'user:pass',
ws: true,
followRedirects: true,
}
]
},
plugins: [
new EnvironmentPlugin({
CRYOSTAT_AUTHORITY: 'http://localhost:8181',
// Requests are proxied by dev-server
// In preview mode, a base url is required.
CRYOSTAT_AUTHORITY: process.env.PREVIEW? 'http://localhost:8181': '',
PREVIEW: process.env.PREVIEW || 'false'
})
],
Expand Down
Loading