기본 콘텐츠로 건너뛰기

Meteor를 client만 사용하기 - Offline Meteor

'뭔소리야 서버부터 클라이언트까지 하나의 언어 하나의 자료형을 쓰는게 Meteor의 장점인데 왜 서버를 분리해?'
라며 당연하고 올바른 생각을 가지고 계신 분이라면 '뒤로 가기' 추천합니다. ^^;;;
Meteor는 좋은데 서버가 자바야, PHP야. 혹은 Cordova(구 phonegap)이나 Chrome Apps같은 분야에 적용하고 싶은데 Meteor로 하고 싶어라고 생각하신다면 추천.

Meteor 프로젝트를 meteor create <...> 로 생성하셨다면 Meteor는 run을 한 시점부터 .meteor/local/build/programs/client 에 클라이언트 쪽 파일들을 생성합니다.

이걸 고대로 떠서 약간의 작업을 하면 서버와 상관없이 사용할 수 있는데.


  1. app.html 의 ##HASH## 들을 삭제한다.
  2. __meteor_runtime_config__ 을 추가하여 ROOT_URL을 지정한다. (보통은 localhost)
  3. package등에서 사용하는 정적 자원에 대한 경로를 수정한다.
8000포트에 할 경우 .html 파일에 아래와 같은 부분을 ##RUNTIME_CONFIG## 있는 곳에 바꿔 넣어줍니다.
  __meteor_runtime_config__={
  ROOT_URL = "http://localhost:8000"
  }

정도가 되겠습니다.
의외로 어렵지 않죠?
근데 실제로 해보면 신경쓸 것들이 좀 있습니다.

제 경우는 디렉토리 구조를 이렇게 잡았습니다.
생성한 과정은 이렇습니다.

$ mkdir pack
$ cd pack
$ meteor create memo
$ mkdir www
$ cd memo

여기까지 하고 client 쪽 코드를 약간 수정합니다.
Meteor는 기본적으로 클라이언트 vs 서버간 websocket통신을 하고 있기 때문에 관련 그 부분을 hack해서 못쓰게 만듭니다.
* memo.js

if (Meteor.isClient) {
  Meteor.connection._stream._retryTimeout = function() { return 365 * 24 * 60 * 60 * 1000 };
  Meteor.connection._stream._lostConnection();
  
  Template.hello.greeting = function () {
    return "Welcome to memo.";
  };

  Template.hello.events({
    'click input' : function () {
      // template data, if any, is available in 'this'
      if (typeof console !== 'undefined')
        console.log("You pressed the button");
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}

$ meteor (혹은 meteor --production)
^c (종료)
$ cd ../www
$ cp -R ../memo/.meteor/local/build/programs/client/. .

$ python -m SimpleHTTPServer
(서버구동)

이 정도가 좋은 출발점이지 않을까 싶습니다.
클릭 이벤트도 잘 먹고 괜찮네요.
사실은 sock.js가 계속 뭔가 통신을 하려고 하는데 이 부분은 서버쪽 구현에서 붙여보면 되겠습니다.

Cordova에서 붙여서 프로젝트 하는 용도로 잘 썼구요.
위의 귀찮은 일련의 작업을 자동화할 수 있는 Gruntfile.js의 신세를 졌습니다.
처음 써봤는데 js버전 ant같은 느낌이더군요. 썩 맘에 들지는 않지만 shell을 짜면 OS 의존성이 생기는 걸 생각하면 나쁘지 않더군요.
다음번엔 go 언어에 한번 붙여서 해볼까 합니다.

댓글

이 블로그의 인기 게시물

세상 간단한 https(+secured websocket): Caddy

nginx, apache2 같은 걸로 매번 certbot 연동을 통해 https 하는게 지겨워서 알아보니 Caddy라는게 있더라. 설치법은 강하게 크기 위해 알아서 해본다. # cat /etc/caddy/Caddyfile your.shitty.site:8123 {   proxy / localhost:9123 {     websocket     transparent   } } 이건 외부에서 8123으로 들어오는 걸 내부적으로 9123로 맞춰서 https 맞춰주는 reverse proxy. 만일 port를 생략하면 # cat /etc/caddy/Caddyfile your.shitty.site {   proxy / localhost:9123 {     websocket     transparent   } } 기본포트인 443으로 되어 https://your.shitty.site 로 접속이 된다. 요새 말썽이던 cloudflare 버리고 netlify domain이랑 caddy를 쓰니까 앓던 이가 빠진 느낌. 이 조합은 당분간 계속 써야겠다 싶다.

저지연 오디오 생성 LLVC 사용기

https://github.com/KoeAI/LLVC 써봄 CUDA 11.8 버전 쓰고 있어 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 VC 없어서 설치 https://wikidocs.net/168848 참조 FAIRSEQ 관련 오류 https://github.com/facebookresearch/fairseq/issues/2908 pip install editdistance  설치 No CUDA runtime is found, using CUDA_HOME='C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8' 오류 멀쩡하게 있는데 안됨. pip install torch==2.1.0+cu118 torchvision==0.16.0+cu118 torchaudio==2.1.0+cu118 --extra-index-url https://download.pytorch.org/whl/cu118 다시 설치 set DISTUTILS_USE_SDK=1 이게 문젠가 설정하고 재도전 Using cached ruamel.yaml.clib-0.2.8-cp311-cp311-win_amd64.whl (118 kB) Building wheels for collected packages: fairseq   Building wheel for fairseq (pyproject.toml) ... error   error: subprocess-exited-with-error   × Building wheel for fairseq (pyproject.toml) did not run successfully.   │ exit code: 1   ╰─> [1829 lines of output]       No CUDA runtime is found, usi...