FEAT: serve the client-side JavaScript at /51Degrees.core.js - #338
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The dotnet, java and rust getting-started-web examples serve the client-side bundle as a separate resource at
/51Degrees.core.jsand 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.js404'd and a page copied from one of the other examples gotfod 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.jsroute returning the JavaScriptBuilder output with theapplication/x-javascriptcontent 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: renderdeviceidin 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-requestfod-js-enable-cookiesquery parameter is picked up as evidence and honoured byJavascriptBuilderElement.The shared
examples.min.jshelper 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/Varyon 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_webstill inlines the script and does not render a device id, so it could get the same treatment.Testing
python -m unittest tests.test_cloudgettingstartedwebpasses (3 tests). The device id test fails as expected when the new table row is removed.curl -sI /51Degrees.core.jsreturns200withContent-Type: application/x-javascriptandContent-Length: 75650, body ends invar 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 rendersDevice Id: 15364-38914-130366-18092./51Degrees.core.js?fod-js-enable-cookies=falsedrops the cookie-writing branch from the generated script;=trueand the default keep it.