English 中文(简体)
Avoiding CORS issues on web app importing JavaScript modules from other domains
原标题:

I am building a web application using NodeJS splitting the application into a back-end to handle database queries with MongoDB and a front end via a node based webserver that uses interactjs with JavaScript compiled from TypeScript. Currently, I have it running on LocalHost.

For my front end, leaning on my desktop application development skills, I originally built an application modularly out of several JS modules in a serverless, on the local machine not even using local host, way. It constructs flowcharts drag and drop style implemented using typescript compiled to JS. I have now moved it into node. Most things seem to be working, but in one of my modules I am importing interact.js to handle my drag and drop.

import interact from  https://cdn.jsdelivr.net/npm/@interactjs/interactjs/index.js 

However, this seems to be causing CORS errors to be reported by my browser Firefox. I have done quite a bit of reading and understand what Cross Origin Resource Sharing is, and why problems occur. However, I have yet to find a good source of information that helps me overcome my problem. A lot of the information seems to either describe what a CORS error is without offering a solution or provides examples mime types,or fetch commands which are not relevant to this (as far as I know).

If you are running a webapp that is at http://localhost:5000/myApp. How then can my code import external JavaScript modules without triggering the CORS errors?

What I am seeing many times over in the console of Firefox s is three likely related errors:

Loading module from “https://cdn.jsdelivr.net/npm/@interactjs/actions/drag/plugin” was blocked because of a disallowed MIME type (“text/plain”).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://cdn.jsdelivr.net/npm/@interactjs/actions/drag/plugin. (Reason: CORS request did not succeed). Status code: (null).

Module source URI is not allowed in this document: “https://cdn.jsdelivr.net/npm/@interactjs/actions/drag/plugin”.

I m posting here out of desperation, as I have spent all day going around in circles and have not been able to find anything related to my problem on StackOverflow or elsewhere.

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签