기본 콘텐츠로 건너뛰기

5월, 2013의 게시물 표시

Meteor에서 REST API를 사용하는 방법 #2

server쪽 API를 router package를 사용해 쓰다보면 header 같은 걸 다루거나 할땐 너무 단순하게 만들어서 곤란할 수 있다. 이전에도 다룬 적( http://spectrumdig.blogspot.kr/2012/08/meteor-rest.html )이 있지만 __meteor_bootstrap__ 객체를 통해 접근하면 node.js 식의 접근이 가능하다. Meteor update와 함께 Npm 객체가 생겼으니 이를 이용해 connect 객체를 사용해보자 http://www.slideshare.net/cjoudrey/building-your-first-node-app-with-connect-express 위 슬라이드를 한번 보면 이해에 도움이 될 것이다. WebApp.connectHandlers 가 connect.createServer()라는 걸 기억하면 된다. connect = Npm.require 'connect' server = WebApp.connectHandlers server.use connect.router (app)-> app.get '/info', (req,res)-> res.end "info" app.get '/user/:id', (req,res)-> res.end "user id: #{req.params.id}" 이와 같은 코드를 server 디렉토리에 안에 넣거나 Meteor.isServer일때 실행하도록 하자. 파일 업로드나 쿼리 문자열 처리(ex: ?a=1&b=c)하려면 각각 bodyParser( http://www.senchalabs.org/connect/bodyParser.html ) 와 query( http://www.senchalabs.org/connect/query.html )를 추가하는 것이 좋다. 위의 해당 링크에 보면 소스까지 공개 해놓아서 이해하기 쉬우니

rvictl로 iOS Network packet을 보자.

iOS 5이후 부턴 USB로 장비를 연결하고 rvictl이란 명령으로 네트워크 패킷을 볼 수 있다고 한다. $ rvictl rvictl [-h][-l][-s <udid1> ... <udidN>][-x <udid1> ... <udidN>] Remote Virtual Interface Tool starts and stops a remote packet capture instance for any set of attached mobile devices. It can also provide feedback on any attached devices that are currently relaying packets back to this host. Options: -l, -L List currently active devices -s, -S Start a device or set of devices -x, -X Stop a device or set of devices 내용은 간단. UDID 입력하고 -s 로 시작 -l로 확인 -x로 정지. 한번 해보자 $ rvictl -s <UDID> Starting device <UDID> [SUCCEEDED] 이런 식으로 나오면 성공. USB연결을 꼭 확인하자. 참고로 iPhone Simulator 에서도 UDID만 있으면 작동한다는 이야기가 있음; 어디다 쓸진 모르겠지만;; 확인해보자. $ rvictl -l Current Active Devices: [1]  <UDID> 아까 그 UDID 가 목록에 있으면 성공. ifconfig 로 잘 들어갔나 확인해보자. $ ifconfig -l lo0 gif0 stf0 en0 p2p0 utun0 rvi0 rvi0이 들어갔으면 성공. $ ifconfig rvi0 rvi0: flags=3005<UP,DEBUG