Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
node-http-proxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
node-http-proxy
Commits
8eaec350
Commit
8eaec350
authored
Jul 28, 2011
by
Charlie McConnell
Committed by
Dominic Tarr
Aug 02, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[minor] Added body decoder middleware example. Needs fixing.
parent
549bfeac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
examples/body-decoder.js
examples/body-decoder.js
+43
-0
No files found.
examples/body-decoder.js
0 → 100644
View file @
8eaec350
#!/usr/local/bin/node
var
httpProxy
=
require
(
'
http-proxy
'
),
http
=
require
(
'
http
'
),
util
=
require
(
'
util
'
),
colors
=
require
(
'
colors
'
);
exports
.
bodyMod
=
function
()
{
console
.
log
(
'
middleware has been started.
'
.
green
);
return
function
(
req
,
res
,
next
)
{
var
proxy
=
next
,
total
=
''
;
req
.
on
(
'
data
'
,
function
(
data
)
{
console
.
log
(
'
ON DATA
'
)
total
+=
data
;
});
req
.
on
(
'
end
'
,
function
()
{
console
.
log
(
'
ON END
'
)
console
.
log
(
total
);
// This line, uncommented, hangs forever.
// proxy.proxyRequest(req, res, { port: 9000, host: 'localhost' });
// The following also hangs forever.
// next.proxyRequest(req, res, { port: 9000, host: 'localhost' });
})
// The following fires just fine.
//proxy.proxyRequest(req, res, { port: 9000, host: 'localhost' });
console
.
log
(
'
request proxied...
'
.
blue
);
}
}
var
proxyServer
=
httpProxy
.
createServer
(
// Your middleware stack goes here.
exports
.
bodyMod
()
).
listen
(
8000
);
var
httpServer
=
http
.
createServer
(
function
(
req
,
res
)
{
res
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
text/plain
'
});
res
.
write
(
'
request successfully proxied to:
'
+
req
.
url
+
'
\n
'
+
JSON
.
stringify
(
req
.
headers
,
true
,
2
));
res
.
end
();
}).
listen
(
9000
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment