2016-08-21 3 views
1

타사 웹 사이트 (예 : 고객 지원 채팅 응용 프로그램)에 삽입되도록 설계된 유성을 사용하여 자바 스크립트 구성 요소를 작성하려고합니다. 이상적으로는 사용자가 자바 스크립트 또는 작은 <script> 태그를 삽입하여 응용 프로그램을 사용할 수있게하고 싶습니다.서버에서 __meteor_runtime_config__ 변수를 가져 오는 방법

일반적인 웹 페이지의 경우, 유성은 중요한 유성 설정이 많은 글로벌 변수 __meteor_runtime_config__을 동적으로 생성하고 주입합니다.

일반적인 유성 .js 번들 파일을 포함하거나 유성 앱을 배포 할 때 번들 파일에 빌드 할 때이 변수의 값을 검색하는 방법은 무엇입니까?

답변

1

이라는 타사 유틸리티를 사용하면 Meteor 앱의 클라이언트 부분을 추출 할 수 있으므로 Meteor 앱의 나머지 부분과 별도로 웹 페이지에 삽입 할 수 있습니다. 그런 다음 추출 된 클라이언트 DDP를 통해 배포 된 Meteor 서버 코드). 이 도구를 사용하면 시간을 절약 할 수 있습니다.

__meteor_runtime_config__ 설정을 사용하는 방법을 계속 알고 싶다면 source of the Meteor Build Client utility을 확인하십시오. 관련 부분을 아래에 게시했습니다 :

... 
// ADD the SCRIPT files 
var scripts = '__meteor_runtime_config__'+ "\n"+ 
'  <script type="text/javascript" src="'+ files['js'] +'"></script>'+ "\n"; 

// add the meteor runtime config 
settings = { 
    'meteorRelease': starJson.meteorRelease, 
    'ROOT_URL_PATH_PREFIX': '', 
    meteorEnv: { NODE_ENV: 'production' }, 
}; 
// on url = "default", we dont set the ROOT_URL, so Meteor chooses the app serving url for its DDP connection 
if(program.url !== 'default') 
    settings.ROOT_URL = program.url || ''; 

if(settingsJson.public) 
    settings.PUBLIC_SETTINGS = settingsJson.public; 

scripts = scripts.replace('__meteor_runtime_config__', '<script type="text/javascript">__meteor_runtime_config__ = JSON.parse(decodeURIComponent("'+encodeURIComponent(JSON.stringify(settings))+'"));</script>'); 
... 
관련 문제