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
c4b7c0d8
Commit
c4b7c0d8
authored
Jul 27, 2010
by
Marak Squires
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updating demo
parent
2f49810e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
99 deletions
+24
-99
demo.js
demo.js
+24
-24
vendor/colors.js
vendor/colors.js
+0
-75
No files found.
demo.js
View file @
c4b7c0d8
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
var
vows
=
require
(
'
vows
'
),
var
vows
=
require
(
'
vows
'
),
sys
=
require
(
'
sys
'
),
sys
=
require
(
'
sys
'
),
colors
=
require
(
'
./vendor/
colors
'
)
colors
=
require
(
'
colors
'
)
assert
=
require
(
'
assert
'
),
assert
=
require
(
'
assert
'
),
http
=
require
(
'
http
'
);
http
=
require
(
'
http
'
);
...
@@ -16,40 +16,40 @@ var HttpProxy = require('./lib/node-http-proxy').HttpProxy;
...
@@ -16,40 +16,40 @@ var HttpProxy = require('./lib/node-http-proxy').HttpProxy;
var
testServers
=
{};
var
testServers
=
{};
// regular http server
// ascii art from http://github.com/marak/asciimo
var
welcome
=
'
\
# # ##### ##### ##### ##### ##### #### # # # #
\n\
# # # # # # # # # # # # # # # #
\n\
###### # # # # ##### # # # # # # ## #
\n\
# # # # ##### ##### ##### # # ## #
\n\
# # # # # # # # # # # # #
\n\
# # # # # # # # #### # # #
\n
'
;
sys
.
puts
(
welcome
.
rainbow
.
bold
);
// create regular http proxy server
http
.
createServer
(
function
(
req
,
res
){
http
.
createServer
(
function
(
req
,
res
){
// Initialize the nodeProxy and start proxying the request
var
proxy
=
new
(
HttpProxy
);
var
proxy
=
new
(
HttpProxy
);
proxy
.
init
(
req
,
res
);
proxy
.
init
(
req
,
res
);
// lets proxy the request to another service
proxy
.
proxyRequest
(
'
localhost
'
,
'
9000
'
,
req
,
res
);
proxy
.
proxyRequest
(
'
localhost
'
,
'
8081
'
,
req
,
res
);
}).
listen
(
8000
);
sys
.
puts
(
'
http proxy server
'
.
blue
+
'
started
'
.
green
.
bold
+
'
on port
'
.
blue
+
'
8000
'
.
yellow
);
}).
listen
(
8080
);
sys
.
puts
(
'
started a http server on port 8080
'
.
green
)
// http server with latency
// http
proxy
server with latency
http
.
createServer
(
function
(
req
,
res
){
http
.
createServer
(
function
(
req
,
res
){
// Initialize the nodeProxy and start proxying the request
var
proxy
=
new
(
HttpProxy
);
var
proxy
=
new
(
HttpProxy
);
proxy
.
init
(
req
,
res
);
proxy
.
init
(
req
,
res
);
// lets proxy the request to another service
setTimeout
(
function
(){
setTimeout
(
function
(){
proxy
.
proxyRequest
(
'
localhost
'
,
'
809
0
'
,
req
,
res
);
proxy
.
proxyRequest
(
'
localhost
'
,
'
900
0
'
,
req
,
res
);
},
200
)
},
200
)
}).
listen
(
8001
);
}).
listen
(
8081
);
sys
.
puts
(
'
http proxy server
'
.
blue
+
'
started
'
.
green
.
bold
+
'
on port
'
.
blue
+
'
8001
'
.
yellow
+
'
with latency
'
.
magenta
.
underline
);
sys
.
puts
(
'
started a http server with latency on port 8081
'
.
green
)
// create regular http server
http
.
createServer
(
function
(
req
,
res
){
http
.
createServer
(
function
(
req
,
res
){
res
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
text/plain
'
});
res
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
text/plain
'
});
res
.
write
(
'
foo
'
);
res
.
write
(
'
foo
'
);
res
.
end
();
res
.
end
();
}).
listen
(
8090
);
}).
listen
(
9000
);
sys
.
puts
(
'
started another http server on port 8090
'
.
green
)
sys
.
puts
(
'
http server
'
.
blue
+
'
started
'
.
green
.
bold
+
'
on port
'
.
blue
+
'
9000
'
.
yellow
);
//sys.puts('to test the proxy server, request http://localhost:8080/ in your browser.');
//sys.puts('your request will proxy to the server running on port 8081');
sys
.
puts
(
'
to test the proxy server, request http://localhost:8080/ in your browser.
'
);
\ No newline at end of file
sys
.
puts
(
'
your request will proxy to the server running on port 8081
'
);
vendor/colors.js
deleted
100644 → 0
View file @
2f49810e
/*
colors.js
Copyright (c) 2010 Alexis Sellier (cloudhead) , Marak Squires
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// prototypes the string object to have additional method calls that add terminal colors
[
'
bold
'
,
'
underline
'
,
'
italic
'
,
'
inverse
'
,
'
grey
'
,
'
yellow
'
,
'
red
'
,
'
green
'
,
'
blue
'
,
'
white
'
,
'
cyan
'
,
'
magenta
'
].
forEach
(
function
(
style
)
{
Object
.
defineProperty
(
String
.
prototype
,
style
,
{
get
:
function
()
{
return
stylize
(
this
,
style
);
}
});
});
// prototypes string with method "rainbow"
// rainbow will apply a the color spectrum to a string, changing colors every letter
Object
.
defineProperty
(
String
.
prototype
,
'
rainbow
'
,
{
get
:
function
()
{
var
rainbowcolors
=
[
'
red
'
,
'
yellow
'
,
'
green
'
,
'
blue
'
,
'
magenta
'
];
//RoY G BiV
var
exploded
=
this
.
split
(
""
);
var
i
=
0
;
exploded
=
exploded
.
map
(
function
(
letter
)
{
if
(
letter
==
"
"
)
{
return
letter
;
}
else
{
return
stylize
(
letter
,
rainbowcolors
[
i
++
%
rainbowcolors
.
length
]);
}
});
return
exploded
.
join
(
""
);
}
});
function
stylize
(
str
,
style
)
{
var
styles
=
{
//styles
'
bold
'
:
[
1
,
22
],
'
italic
'
:
[
3
,
23
],
'
underline
'
:
[
4
,
24
],
'
inverse
'
:
[
7
,
27
],
//grayscale
'
white
'
:
[
37
,
39
],
'
grey
'
:
[
90
,
39
],
'
black
'
:
[
90
,
39
],
//colors
'
blue
'
:
[
34
,
39
],
'
cyan
'
:
[
36
,
39
],
'
green
'
:
[
32
,
39
],
'
magenta
'
:
[
35
,
39
],
'
red
'
:
[
31
,
39
],
'
yellow
'
:
[
33
,
39
]
};
return
'
\
033[
'
+
styles
[
style
][
0
]
+
'
m
'
+
str
+
'
\
033[
'
+
styles
[
style
][
1
]
+
'
m
'
;
};
\ 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