couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [9/13] git commit: A /_nodejs handler to forward to the node app
Date Wed, 13 Feb 2013 13:17:14 GMT
A /_nodejs handler to forward to the node app


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/b7eb2af7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/b7eb2af7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/b7eb2af7

Branch: refs/heads/nodejs_couchdb
Commit: b7eb2af759d06533844507719756d4533db2f1b3
Parents: a02acbe
Author: Jason Smith (work) <jhs@iriscouch.com>
Authored: Tue Feb 12 16:03:12 2013 +0000
Committer: Jason Smith (work) <jhs@iriscouch.com>
Committed: Tue Feb 12 16:03:12 2013 +0000

----------------------------------------------------------------------
 etc/couchdb/default.ini.tpl.in     |    1 +
 src/couchdb/Makefile.am            |    2 +
 src/couchdb/couch_httpd_nodejs.erl |  121 +++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/b7eb2af7/etc/couchdb/default.ini.tpl.in
----------------------------------------------------------------------
diff --git a/etc/couchdb/default.ini.tpl.in b/etc/couchdb/default.ini.tpl.in
index a2cdf49..865ec85 100644
--- a/etc/couchdb/default.ini.tpl.in
+++ b/etc/couchdb/default.ini.tpl.in
@@ -158,6 +158,7 @@ _log = {couch_httpd_misc_handlers, handle_log_req}
 _session = {couch_httpd_auth, handle_session_req}
 _oauth = {couch_httpd_oauth, handle_oauth_req}
 _debug = {couch_httpd_debug, handle_debug_req}
+_nodejs = {couch_httpd_nodejs, handle_node_req}
 
 [httpd_db_handlers]
 _all_docs = {couch_mrview_http, handle_all_docs_req}

http://git-wip-us.apache.org/repos/asf/couchdb/blob/b7eb2af7/src/couchdb/Makefile.am
----------------------------------------------------------------------
diff --git a/src/couchdb/Makefile.am b/src/couchdb/Makefile.am
index fd86d59..110f9e6 100644
--- a/src/couchdb/Makefile.am
+++ b/src/couchdb/Makefile.am
@@ -51,6 +51,7 @@ source_files = \
     couch_httpd_auth.erl \
     couch_httpd_cors.erl \
     couch_httpd_debug.erl \
+    couch_httpd_nodejs.erl \
     couch_httpd_oauth.erl \
     couch_httpd_external.erl \
     couch_httpd_misc_handlers.erl \
@@ -110,6 +111,7 @@ compiled_files = \
     couch_httpd_oauth.beam \
     couch_httpd_cors.beam \
     couch_httpd_debug.beam \
+    couch_httpd_nodejs.beam \
     couch_httpd_proxy.beam \
     couch_httpd_external.beam \
     couch_httpd_misc_handlers.beam \

http://git-wip-us.apache.org/repos/asf/couchdb/blob/b7eb2af7/src/couchdb/couch_httpd_nodejs.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_nodejs.erl b/src/couchdb/couch_httpd_nodejs.erl
new file mode 100644
index 0000000..fc14983
--- /dev/null
+++ b/src/couchdb/couch_httpd_nodejs.erl
@@ -0,0 +1,121 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License.  You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_httpd_nodejs).
+-include("couch_db.hrl").
+
+-export([handle_node_req/1]).
+
+-import(couch_httpd, [header_value/2, send_method_not_allowed/2]).
+
+
+handle_node_req(#httpd{}=Req) -> ok
+    , couch_httpd:send_json(Req, 200, {[ {ok,true}, {todo,true} ]}).
+
+%handle_git_req(#httpd{method='GET', path_parts=[_Debug, Pid | _Rest]=Path}=Req) -> ok
+%    , ok = couch_httpd:verify_is_server_admin(Req)
+%    %, io:format("Must look up: ~p for: ~p\n", [Pid, Path])
+%    , Procs = couch_query_servers:git_ports("javascript")
+%    , case lists:keyfind(Pid, 1, Procs)
+%        of {Pid, Port} -> ok
+%            % Proxy to socket.io. Use the normal httpd_proxy for everything except the
+%            % websockets request.
+%            , InspectorPort = Port + 1
+%            , case Path
+%                of [<<"_git">>, Pid, <<"socket.io">>, <<"1">>,
<<"websocket">>, _Key] -> ok
+%                    , relay(Req, InspectorPort)
+%                ; _ -> ok
+%                    , Url = io_lib:format("http://127.0.0.1:~w/_git/", [InspectorPort])
+%                    %, io:format("Proxy: ~p\nPath = ~p\n", [Url, Path])
+%                    , couch_httpd_proxy:handle_proxy_req(Req, ?l2b(Url))
+%                end
+%        ; false -> ok
+%            , io:format("No such pid: ~p\n", [Pid])
+%            , couch_httpd:send_json(Req, 404, {[ {error,pid_not_found}, {pid,Pid} ]})
+%        end
+%    ;
+%
+%handle_git_req(Req) -> ok
+%    , send_method_not_allowed(Req, "GET")
+%    .
+%
+%relay(Req, Port) when is_integer(Port) -> ok
+%    , io:format("socket.io connection to port ~w\n", [Port])
+%    , case gen_tcp:connect("127.0.0.1", Port, [binary, {packet,0}, {active,false}])
+%        of {ok, InspectorSocket} -> ok
+%            , io:format("Connected to inspector on :~w\n", [Port])
+%            , relay(Req, InspectorSocket)
+%        ; {error, Error} -> ok
+%            , Resp = {[ {error,inspector_proxy}, {result, Error} ]}
+%            , couch_httpd:send_json(Req, 502, Resp)
+%        end
+%    ;
+%
+%relay(#httpd{mochi_req=MochiReq}=Req, InspectorSocket) -> ok
+%    , Client = MochiReq:get(socket)
+%    , ReqBytes = request_to_iolist(Req)
+%    , Size = iolist_size(ReqBytes)
+%    , io:format("Send ~w byte request to inspector\n", [Size])
+%    , ok = gen_tcp:send(InspectorSocket, ReqBytes)
+%    , relay(Client, InspectorSocket, Size, 0)
+%    .
+%
+%relay(Client, Remote, FromClient, FromRemote) -> ok
+%    %, io:format("Relay client=~w remote=~w\n", [FromClient, FromRemote])
+%    , inet:setopts(Client, [{packet,0}, {active,once}, {nodelay,true} ])
+%    , inet:setopts(Remote, [{packet,0}, {active,once}, {nodelay,true} ])
+%    , receive
+%        {_Type, Client, Data} -> ok
+%            %, io:format("Client: ~p\n", [Data])
+%            , gen_tcp:send(Remote, Data)
+%            , relay(Client, Remote, FromClient + size(Data), FromRemote)
+%        ; {_Type, Remote, Data} -> ok
+%            %, io:format("Remote ~w bytes: ~p\n", [size(Data), Data])
+%            , gen_tcp:send(Client, Data)
+%            , relay(Client, Remote, FromClient, FromRemote + size(Data))
+%        ; {tcp_closed, Client} -> ok
+%            , io:format("Client disconnected\n")
+%            , gen_tcp:close(Remote)
+%            , {ok, ok}
+%        ; {tcp_closed, Remote} -> ok
+%            % XXX
+%            , io:format("Remote disconnected\n")
+%            %, gen_tcp:controlling_process(Remote)
+%            %, catch Owner ! {stream_close, bad_reqid}
+%            , gen_tcp:close(Client)
+%            %, {ok, FromClient, FromRemote}
+%            , {ok, ok}
+%        ; Else -> ok
+%            , ?LOG_ERROR("Relay error: ~p", [Else])
+%        end
+%    %, couch_httpd:send_json(Req, 200, {[ {ok,true}, {todo,<<"To do">>} ]})
+%    .
+%
+%request_to_iolist(#httpd{method=Method, mochi_req=MochiReq}) -> ok
+%    , Path = MochiReq:get(raw_path)
+%    , Version = case MochiReq:get(version)
+%        of {1,1} -> "1.1"
+%        ;  _     -> "1.0"
+%        end
+%    , Action = io_lib:format("~s ~s HTTP/~s", [Method, Path, Version])
+%    , MochiHeaders = mochiweb_headers:to_list(MochiReq:get(headers))
+%    , Headers = [ [couch_util:to_binary(Key), ": ", Val, "\r\n"] || {Key, Val} <- MochiHeaders]
+%    , [Action, "\r\n", Headers, "\r\n"]
+%    .
+
+
+%
+% Utilities
+%
+
+
+% vim: sts=4 sw=4 et


Mime
View raw message