Skip to content

Conversation

@Ehevi
Copy link

@Ehevi Ehevi commented Sep 6, 2025

I DON'T have JIRA ticket

  • explain what this PR does
  • if it is new feature explain how plan to use it
  • test are added
  • documentation is changed or added
  • FLP integration tests were ran successful

Summary

Make the tutorial run under the framework’s default Content Security Policy (CSP) and align the docs with the actual files. The previous tutorial used an inline <script> which modern browsers block when CSP includes script-src 'self'. It also referenced a legacy compatibility.js that isn’t shipped, causing a 404. This PR moves controller code into ES modules, removes the unused script, fixes a case-sensitive import, and updates the tutorial document.

What changed

  • Framework/docs/tutorial/public/index.html

    • Replace inline controller with:
    <script type="module" src="./session.js"></script>
    <script type="module" src="./app.js"></script>
    
    • Remove <script src="/js/src/compatibility.js"></script> (not shipped; produced 404).
  • Framework/docs/tutorial/public/session.js (new)

    • Minimal session bootstrap: sessionService.loadAndHideParameters().
  • Framework/docs/tutorial/public/app.js (new)

    • Main controller: imports view and Model and calls mount(document.body, view, model, true).
    • Exposes window.model for easy console debugging in the tutorial (non-production).
  • Framework/docs/tutorial/time-server.md

    • Refresh “Files overview” as a tree.
    • Update the Controller section to use session.js and app.js.
    • Add a short CSP note explaining why inline scripts are avoided.
    • Fix Model import case (./Model.js) to match the file name.
    • Minor grammar/clarity edits.

Why

  • Default CSP includes script-src 'self', which blocks inline modules; external ES modules keep the example secure and working out-of-the-box.

  • compatibility.js is a legacy shim that isn’t included by current builds and isn’t needed here; leaving it causes a 404.

  • Import case (Model.js vs model.js) matters on case-sensitive filesystems and previously caused a 404.

Scope / risk

Docs + tutorial assets only. No framework/runtime behavior changes. Low risk.

Adjust the time-server readme

Grammar fixes

Remove the compatibility.js include
@Ehevi Ehevi force-pushed the time-server-tutorial-fix branch from 26eb435 to 8ef7244 Compare September 6, 2025 17:35
<!doctype html>
<title>Tutorial - Time server</title>
<link rel="stylesheet" href="/css/src/bootstrap.css">
<script src="/js/src/compatibility.js"></script>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compatibility.js is a legacy shim that isn’t shipped by current@aliceo2/web-ui builds and isn’t needed for this tutorial; keeping it produced a 404, so it’s removed.

Screenshot 2025-09-06 at 19 26 44

Comment on lines -7 to +9
<script type="module">
import sessionService from '/js/src/sessionService.js';
sessionService.loadAndHideParameters();
</script>
<script type="module" src="./session.js"></script>

<!-- Main application controller -->
<script type="module">
// Import MVC
import {mount} from '/js/src/index.js';
import view from './view.js';
import Model from './Model.js';

// Start application
const model = new Model();
const debug = true; // shows when redraw is done
mount(document.body, view, model, debug);

// Expose model to interract with it the browser's console
window.model = model;
</script>
<script type="module" src="./app.js"></script>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading the controller via ES modules avoids inline <script> so the tutorial works under the default CSP (script-src 'self').

Screenshot 2025-09-06 at 17 06 24

mount(document.body, view, model, debug);
```

This avoids inline `<script>` and works with the framework’s default Content Security Policy.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a short CSP explanation to preempt confusion if someone tries to inline scripts and hits browser blocks.

The following `this._prepareWebSocket()` method (note that by convention all method names prepended with `_` are private) listens to two events:
- `authed` - notifies that client has successfully authorized by the server (automatically generated by server)
- `server-date` - custom message that includes server's time (as defined in the [Explaining server side](#explaining-server-side) section - look for `wsServer.bind`)
- `server-date` - custom message that includes server's time (as defined in the [Server side explained](#server-side-explained) section - look for `wsServer.bind`)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the correct section to link to is:
https://github.com/AliceO2Group/WebUi/blob/dev/Framework/docs/tutorial/time-server.md#server-side-explained

The previous anchor #explaining-server-side does not exist.

@Ehevi Ehevi marked this pull request as ready for review September 6, 2025 18:05
@Ehevi Ehevi requested a review from graduta as a code owner September 6, 2025 18:05
@Ehevi Ehevi changed the title Framework/tutorial: move inline controller to app.js Fix Framework/tutorial: CSP violation from inline scripts; use ES modules + docs refresh Sep 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant