2017-03-21 11 views
0

CodeMirror 텍스트 편집기에 내 ANTLR4 파서를 통합하려고합니다. 내 html 파일에 다음 줄을 추가 할 때 : 나는 크롬에서 다음과 같은 오류가납니다CodeMirror에서 ANTLR 파서 사용

var antlr4 = require('antlr4/index'); // index is an ANTLR runtime file 

: 그래서

Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///home/enes/Desktop/git/text_editor_mirror/antlr4/index.js'. 
at require (file:///home/enes/Desktop/git/text_editor_mirror/lib/require.js:179:10) 
at file:///home/enes/Desktop/git/text_editor_mirror/index.html:411:16 

XMLHttpRequest cannot load file:///home/enes/Desktop/git/text_editor_mirror/antlr4/index.js. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource. 

, 어떻게이 문제를 해결할 수

?

답변

0

브라우저가 로컬 파일 시스템에서 파일을 가져 오려고 시도하기 때문에이 오류가 발생합니다 (file:/// 오류가 발생 함). 서버 (http://)에서 js 파일 (antlr 런타임 파일 및 생성 된 js 파일)을 제공해야합니다. Python-Flask은 서버를 통해 js 파일을 쉽게 호스트하는 데 사용할 수 있습니다.

는 함께 보안 웹 사이트를 실행하는 로컬 파일 시스템에서로드 된 스크립트를 허용하지 않는 Flask
http://flask.pocoo.org/docs/0.12/api/#flask.send_from_directory

브라우저를 사용하여 파일을 제공하기 위해 링크를 따라. 그래서 서버에서 스크립트를 호출해야하는 것을 피하기 위해. 로컬 서버가 도움이되지 않는다면이 스크립트를 Github으로 푸시하고 Gitraw와 같은 CDN 서비스를 사용하여 호출 할 수 있습니다.