Skip to content

Conversation

@andrewazores
Copy link
Member

@andrewazores andrewazores commented Jun 11, 2024

Welcome to Cryostat! 👋

Before contributing, make sure you have:

  • Read the contributing guidelines
  • Linked a relevant issue which this PR resolves
  • Linked any other relevant issues, PR's, or documentation, if any
  • Resolved all conflicts, if any
  • Rebased your branch PR on top of the latest upstream main branch
  • Attached at least one of the following labels to the PR: [chore, ci, docs, feat, fix, test]
  • Signed all commits using a GPG signature

To recreate commits with GPG signature git fetch upstream && git rebase --force --gpg-sign upstream/main


Fixes: #1271

How to manually test:

  1. Check out PR
  2. yarn start:dev:preview should bring up the preview/demo UI. There should be a Fake Target, with a Demo template. Topology view should work, dashboard should work, recording start/stop/archive/delete should work, expanding recording for automated analysis should work. GraphQL-powered things will not work, snapshot recording creation does not work.
  3. yarn run build:preview:notests && cd dist && python3 -m http.server, then open http://localhost:8000 in a browser. The preview should work just the same as in the step above.

@github-actions github-actions bot added the needs-triage Needs thorough attention from code reviewers label Jun 11, 2024
@tthvo
Copy link
Member

tthvo commented Jun 11, 2024

Would this patch help? The mock code just needs to get the same wsUrl as in the application code.

diff --git a/src/mirage/index.ts b/src/mirage/index.ts
index 61f75db..abea4bf 100644
--- a/src/mirage/index.ts
+++ b/src/mirage/index.ts
@@ -20,11 +20,12 @@ import { Server as WSServer, Client } from 'mock-socket';
 import factories from './factories';
 import models from './models';
 import { Resource } from './typings';
-import { sizeUnits } from 'src/app/utils/utils';
 
 export const startMirage = ({ environment = 'development' } = {}) => {
-  const wsUrl = `ws://localhost:9091/api/notifications`;
-  const wsServer = new WSServer(wsUrl);
+  const wsUrl = new URL(window.location.href);
+  wsUrl.protocol = wsUrl.protocol.replace('http', 'ws');
+  wsUrl.pathname = '/api/notifications';
+  const wsServer = new WSServer(wsUrl.toString());
 
   // Create a mock server socket to send notifications
   let websocket: Client;

I tested with and it seemed OK :D

yarn build:preview:notests
cd dist && npx browser-sync start --server

@andrewazores
Copy link
Member Author

Nice, that seems to work. I did the same build-and-local-webserver trick, except instead of npx browser-sync I used python3 -m http.server - same idea.

Want to commit that patch to this branch so you get credited for the contribution? :)

@andrewazores andrewazores removed the needs-triage Needs thorough attention from code reviewers label Jun 12, 2024
@andrewazores andrewazores changed the title test(mirage): set server authority string in preview builds test(mirage): correct server authority string in preview builds Jun 12, 2024
@tthvo
Copy link
Member

tthvo commented Jun 12, 2024

Haha nicee, sure :D I don't have access to your fork though so I opened: andrewazores#2

fix(mirage): ensure wsUrl matches that in application code
@andrewazores
Copy link
Member Author

Ah right, that would be a maintainer privilege that I can add commits to peoples' PRs like that...

@andrewazores andrewazores marked this pull request as ready for review June 12, 2024 17:55
@andrewazores andrewazores requested review from aali309 and mwangggg June 12, 2024 17:55
@andrewazores andrewazores merged commit 3aaeead into cryostatio:main Jun 12, 2024
@andrewazores andrewazores deleted the preview-host branch June 12, 2024 18:31
mergify bot pushed a commit that referenced this pull request Jun 12, 2024
* test(mirage): set server authority string in preview builds

* fix(mirage): ensure wsUrl matches that in application code

---------

Co-authored-by: Thuan Vo <[email protected]>
(cherry picked from commit 3aaeead)
andrewazores added a commit that referenced this pull request Jun 12, 2024
… (#1285)

* test(mirage): set server authority string in preview builds

* fix(mirage): ensure wsUrl matches that in application code

---------

Co-authored-by: Thuan Vo <[email protected]>
(cherry picked from commit 3aaeead)

Co-authored-by: Andrew Azores <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] surge.sh preview has WebSocket error

3 participants