Creating a SDK using Glitch

Being new the NODE JS world a few months ago this platform has REALLY helped me learn so first i want to thank you all!!

I have a project that I need to create an SDK or JS Library to be included in a webpage to expose the functions. I know that a Glitch projects does that with the index.html and the client.js. So I know how to set it up and how to fire the functions in a Script tag in the HTML.

I know you can gain access to the client.js in a project from the outside since I took the below url and it opened the js file. I assume that is because it’s in a public folder.

https://.glitch.me/client.js?

What suggestions would you have in creating a SDK to be used in the above case? Best place to store it? I assume that using the client.js from a project as the SDK would really be the right way to do this. Is there a way to hide the code - scramble it?

Sorry for the newbie questions lol. Thanks!

What’s the motivation for scrambling/hiding the code? There’s not really a way to do that on the client-side, you’d be better off exposing API end-points from the server-side and handling the requests and returning a response if it’s important to hide how the code works.

1 Like

Great - I had the same thought.

So on the other questions. What is the best way to create the SDK using Glitch?

What I have done so far is:

  1. Created a project. I am using the client.js file since it is exposed to the outside world. I have striped all code out and have one function.

  2. I included that JS file in the HTML of an external website. It sees it and I am able to fire the function off.

  3. Problem comes when I use HTTP to fire off the API endpoint. Failed to load https://ember-mastodon.glitch.me/saveData: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. The issue is I am calling an endpoint on another server so the cross domain is getting triggered by the browser i guess - all new to me.

How do I get past this? I have seen other JS files process widgets that connect to another domain with no issues.

So is there a way to whitelist a domain on glitch?

I have trying to figure out how to get past the error in the previous message. Trying to understand how a website widget from ManyChat can work just fine with their JS file and talk from one domain to the other. And when setting up the website widget in MC they ask for the domain where the widget will reside - to whitelist the domain - hence to not get the error I am getting.

So back to the question above - can i whitelist a domain in Gltich so that the API endpoint can be called in the JS file rendered on the website?

Actually found this - I think this is the answer to getting this to work!