Skip to content

Commit 74e0a04

Browse files
Big Changes
1 parent bf9b7b4 commit 74e0a04

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ You CANNOT deploy to Netifly, GitHub Pages, or Cloudflare pages. They are static
3535
<br>
3636
<br>
3737
<a href="https://alienhub.xyz/?utm_source=incog_lite_gh&utm_medium=amethystnetwork">
38-
<img src="https://alienhub.xyz/alien1.gif" width="450" height="150"></img>
38+
<img src="https://alienhub.xyz/images/ad-c8de3fef-bff1-4963-a417-3995855d70e0.gif" width="450" height="150"></img>
3939
</a>
4040
</div>
4141

buffy.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// https://github.com/retronbv/buffy
2+
3+
import axios from "axios";
4+
5+
export default class Buffy {
6+
constructor(opts) {
7+
this.url = new URL(opts.url).toString();
8+
if(this.url.endsWith("/")) this.url = this.url.slice(0, this.url.length - 1);
9+
this.validateStatus = opts.validateStatus ? opts.validateStatus : (status) => status >= 200 && status < 300;
10+
}
11+
12+
/**
13+
* Proxy a Request
14+
* @param {Request} req
15+
* @param {Response} res
16+
* @param {Function} next
17+
*/
18+
async request(req, res, next) {
19+
try {
20+
// Get the asset from the website as a Stream
21+
const response = await axios({
22+
method: req.method,
23+
url: this.url + req.url,
24+
responseType: "stream",
25+
validateStatus: this.validateStatus
26+
});
27+
// Send the HTTP status code and the MIME type
28+
res.writeHead(response.status, { "Content-Type": response.headers.get("content-type").split(";")[0] });
29+
// Pipe the asset to the response
30+
response.data.pipe(res);
31+
} catch(error) {
32+
next();
33+
}
34+
}
35+
}

index.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import createBareServer from "@tomphttp/bare-server-node";
22
import { uvPath } from "@titaniumnetwork-dev/ultraviolet";
33

4-
import axios from "axios";
54
import http from "node:http";
6-
75
import serveStatic from "serve-static";
86
import connect from "connect";
7+
import Buffy from "./buffy.js";
98

109
console.log(`
1110
██████╗ ██╗ ██╗███████╗███████╗██╗ ██╗
@@ -19,6 +18,14 @@ console.log(`
1918
// The following message MAY NOT be removed
2019
console.log("Incognito-Lite\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it\nunder the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nYou should have received a copy of the GNU General Public License\nalong with this program. If not, see <https://www.gnu.org/licenses/>.\n");
2120

21+
const proxy = new Buffy({
22+
url: "https://amethystnetwork-dev.github.io/Incognito/static",
23+
validateStatus: (status) => status !== 404
24+
}); // Proxy the static folder
25+
const gs = new Buffy({
26+
url: "https://amethystnetwork-dev.github.io/Incognito/gsource",
27+
validateStatus: (status) => status !== 404
28+
}); // Proxy the game files
2229
const app = connect();
2330
const bare = createBareServer("/bare/");
2431
const server = http.createServer();
@@ -28,21 +35,8 @@ app.use((req, res, next) => {
2835
});
2936

3037
app.use("/service", (req, res) => res.end("OK"));
31-
32-
app.use(async (req, res, next) => {
33-
try {
34-
const response = await axios({
35-
method: req.method,
36-
url: "https://amethystnetwork-dev.github.io/Incognito/static" + req.url,
37-
responseType: "stream",
38-
validateStatus: (status) => status !== 404
39-
});
40-
res.writeHead(response.status, { "Content-Type": response.headers.get("content-type").split(";")[0] });
41-
response.data.pipe(res);
42-
} catch {
43-
next();
44-
}
45-
});
38+
app.use("/source", (req, res, next) => gs.request(req, res, next));
39+
app.use((req, res, next) => proxy.request(req, res, next));
4640

4741
app.use("/uv", serveStatic(uvPath));
4842

0 commit comments

Comments
 (0)