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
f6484de4
Commit
f6484de4
authored
Jul 26, 2011
by
Dominic Tarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[doc] add comments to examples/url-middleware.js
parent
45f3df80
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
examples/url-middleware.js
examples/url-middleware.js
+9
-7
No files found.
examples/url-middleware.js
View file @
f6484de4
/*
/*
gzip
-middleware.js: Basic example of middleware in node-http-proxy
urls
-middleware.js: Basic example of middleware in node-http-proxy
Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, Marak Squires, & Dominic Tarr.
Copyright (c) 2010 Charlie Robbins, Mikeal Rogers, Fedor Indutny, Marak Squires, & Dominic Tarr.
...
@@ -30,7 +30,9 @@ var util = require('util'),
...
@@ -30,7 +30,9 @@ var util = require('util'),
httpProxy
=
require
(
'
./../lib/node-http-proxy
'
);
httpProxy
=
require
(
'
./../lib/node-http-proxy
'
);
//
//
// Basic Http Proxy Server
// url proxying middleware example.
//
// this is not optimised or tested but shows the basic approch to writing a middleware.
//
//
function
matcher
(
url
,
dest
)
{
function
matcher
(
url
,
dest
)
{
var
r
=
new
RegExp
(
url
)
var
r
=
new
RegExp
(
url
)
...
@@ -54,19 +56,19 @@ exports.urls = function (urls) {
...
@@ -54,19 +56,19 @@ exports.urls = function (urls) {
return
function
(
req
,
res
,
next
)
{
return
function
(
req
,
res
,
next
)
{
//
//
// in nhp middlewares, `proxy` is the prototype of `next`
// in nhp middlewares, `proxy` is the prototype of `next`
// (this means nhp middlewares support both connect API (req, res, next)
// and nhp API (req, res, proxy)
//
//
var
proxy
=
next
;
var
proxy
=
next
;
for
(
var
k
in
matchers
)
{
for
(
var
k
in
matchers
)
{
var
m
var
m
;
if
(
m
=
matchers
[
k
](
req
.
url
))
{
if
(
m
=
matchers
[
k
](
req
.
url
))
{
req
.
url
=
m
.
url
req
.
url
=
m
.
url
;
return
proxy
.
proxyRequest
(
req
,
res
,
m
.
dest
)
return
proxy
.
proxyRequest
(
req
,
res
,
m
.
dest
)
;
}
}
}
}
}
}
}
}
httpProxy
.
createServer
(
httpProxy
.
createServer
(
...
...
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