Skip to content

FEAT: serve the client-side JavaScript at /51Degrees.core.js - #338

Merged
Automation51D merged 2 commits into
mainfrom
feature/serve-core-js-endpoint
Aug 6, 2026
Merged

FEAT: serve the client-side JavaScript at /51Degrees.core.js#338
Automation51D merged 2 commits into
mainfrom
feature/serve-core-js-endpoint

Conversation

@justadreamer

@justadreamer justadreamer commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Why

The dotnet, java and rust getting-started-web examples serve the client-side bundle as a separate resource at /51Degrees.core.js and reference it with a <script src> tag. That path is the endpoint name in the pipeline specification. The python cloud example instead inlined the script into the page, so /51Degrees.core.js 404'd and a page copied from one of the other examples got fod is undefined.

Moving the bundle out of the page then exposed a second gap: the device id was never rendered by this example, it only appeared incidentally inside the JSON blob of the inlined script. The dotnet example renders it as a property in its own right, so python now does too.

What changed

  • cloud/gettingstarted_web/app.py: new /51Degrees.core.js route returning the JavaScriptBuilder output with the application/x-javascript content type used by the other APIs.
  • cloud/gettingstarted_web/templates/index.html: load the bundle with <script src="/51Degrees.core.js"> instead of inlining it.
  • cloud/gettingstarted_web/templates/index.html: render deviceid in the server-side property table, with the label and placement used by the dotnet example.
  • tests/test_cloudgettingstartedweb.py: assert the route returns the bundle with that content type, and that the page renders a device id that is not the all-zero one.

There is no Flask web integration in pipeline-python, so the example wires up the route itself. It builds the flow data from webevidence(request) as the other routes do, which means the per-request fod-js-enable-cookies query parameter is picked up as evidence and honoured by JavascriptBuilderElement.

The shared examples.min.js helper does not render a device id in the client-side refined results, so the device id is server-side only here.

The spec also asks a web integration to set Cache-Control/ETag/Vary on this endpoint. That is deliberately left out: it is web-integration machinery rather than example code, and pipeline-python has no package to put it in.

onpremise/gettingstarted_web still inlines the script and does not render a device id, so it could get the same treatment.

Testing

  • python -m unittest tests.test_cloudgettingstartedweb passes (3 tests). The device id test fails as expected when the new table row is removed.
  • Ran the example against the live cloud endpoint: curl -sI /51Degrees.core.js returns 200 with Content-Type: application/x-javascript and Content-Length: 75650, body ends in var fod=new fiftyoneDegreesManager();.
  • / still renders and still returns server-side detection results (Apple / iOS 15.2 / Mobile Safari for an iPhone user agent), and the callback URL in the served script still points at /json.
  • / for a desktop Chrome user agent renders Device Id: 15364-38914-130366-18092.
  • /51Degrees.core.js?fod-js-enable-cookies=false drops the cookie-writing branch from the generated script; =true and the default keep it.

The dotnet, java and rust getting-started-web examples expose the client-side
bundle as a separate resource at /51Degrees.core.js, which is the endpoint name
in the pipeline specification. Python inlined the same script into the page, so
a page copied from one of the other examples got "fod is undefined".

There is no Flask web integration in pipeline-python, so the example adds the
route itself and returns the JavaScriptBuilder output with the
application/x-javascript content type used by the other APIs.
Moving the client-side bundle to its own URL took the device id off the page:
it was never rendered, it only appeared incidentally inside the JSON blob of
the inlined script. Render it properly alongside the other detected properties,
matching the label and placement used by the dotnet example.
@Automation51D
Automation51D merged commit a215891 into main Aug 6, 2026
1 check passed
@Automation51D
Automation51D deleted the feature/serve-core-js-endpoint branch August 6, 2026 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants