-
Notifications
You must be signed in to change notification settings - Fork 0
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
Experiment with JS and backends #18
Comments
I've finished the experiments successfully. This is the report. ObjectiveThe objective of the experiments was to determine if GitHub pages could host a static webpage able to retrieve data from an API belonging from us (see asrob-uc3m/actas#87 (comment)). As @PeterBowman mentioned in the original thread saving us some headaches, the Same-origin Policy prevents browsers from doing requests to a different origin (domain, port or protocol). There are two ways of avoiding this policy:
ExperimentsFor the experiments I used CORS as it seemed to me that it would be easier to keep a more standard API by returning JSON data instead of a JS file for JSONP. To test that this could indeed work, I set up a simple local backend server in my PC using hug: import hug
@hug.response_middleware()
def alow_origin(request, response, _):
response.set_header('Access-Control-Allow-Origin', '*')
@hug.get('/')
def getdata():
data = {'name':'Dédalo', 'working':True, 'type': 'Prusa i2'}
return data The code of this server just returned some test data in JSON format:
For the frontend I added a testing page to my personal webpage, which uses Jekyll to generate a static website and is hosted using GitHub pages: http://destevez.me/testing. This page uses AngularJS to display the data requested to the backend, whose url has to be set up in the input field. Once the button is clicked, the request is sent and the received data is displayed in the page. I tested this with the frontend page both in a local Jekyll server and in GitHub pages. I also connected this frontend with the backend using a local url (localhost:8000) and over the internet though my router, and it worked in both cases. Even though I did not test it with the GitHub API, I read in the docs that they support both CORS and JSONP, so in principle we could implement an always-updated printers status website, for instance. ConclusionsSince we are going to design and implement the API, we are in control of the backend server. This makes it very easy for us to add the required headers to implement CORS, so I would stick to it instead of JSONP. One thing I did not test and could be an issue is performing the authentication. But since we do not know how to implement the authentication yet, I guess this is something our future-selves will have to deal with. I'll call it a success and close this issue now. Bonus |
As part of the upcoming printer reservation web we had the idea of using JS in a static webpage such as this to render dynamic contents obtained from a backend.
To test whether this is possible or not, I'm going to do a small proof of concept with a web that queries the GitHub API to keep an updated list of ASROB members.
This proof of concept will provide us useful information for our developments in the printer reservation web and to decide which approach is better in the website redirection.
The text was updated successfully, but these errors were encountered: