Skip to content

Commit 8a9f1cf

Browse files
committed
more
1 parent b8d50a3 commit 8a9f1cf

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

example/config/config.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
module.exports = {
22
proxy: [
33
{
4-
forward: ['beach.jpg', 'api-proxy/example'],
5-
target: 'www.google.nl',
6-
},
7-
{
8-
forward: ['api/example-api-2', 'image.svg'],
9-
target: 'www.github.com',
10-
protocol: 'http'
4+
forward: ["todos"],
5+
target: "jsonplaceholder.typicode.com/todos/1",
6+
protocol: "https",
117
},
128
],
139
};

example/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ <h1>Single Page App HTTP Server</h1>
1414
<img src="beach.jpg" alt="" width="500px" alt="beach" />
1515

1616
<p>This <a href="/../../etc/passwd">link</a> should not work</p>
17+
<button id="get-data">Get some data using the proxy</button>
18+
<div id="data"></div>
1719
</div>
1820
</body>
21+
<script>
22+
const options = {
23+
method: "GET",
24+
headers: {
25+
"X-User-Agent": "desktop",
26+
},
27+
};
28+
29+
const btn = document.querySelector("#get-data");
30+
const dataDiv = document.querySelector("#data");
31+
btn.addEventListener("click", () => {
32+
// fetch("/todos/1", options)
33+
fetch("/todos/1", options)
34+
.then((res) => res.json())
35+
.then((d) => (dataDiv.innerHTML = JSON.stringify(d)))
36+
.catch(console.error);
37+
});
38+
</script>
1939
</html>

lib/proxy.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ function proxyHandler(req, res, configs) {
4141
);
4242

4343
if (proxyServer === null) {
44-
proxyServer = httpProxy.createProxyServer({});
44+
proxyServer = httpProxy.createProxyServer({
45+
secure: false,
46+
});
4547
}
4648

4749
proxyServer.web(req, res, {

0 commit comments

Comments
 (0)