forked from Emory81/Transcend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (48 loc) · 1.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { createBareServer } from "@tomphttp/bare-server-node";
import express from "express";
import http from "node:http";
const app = express();
const bare = createBareServer("/bare/");
const server = http.createServer();
const PORT = 8080;
// discord redirect,
app.use("/discord", (req, res) => {
res.redirect("https://discord.gg/49tgKgJx9z");
});
// hwhelp redirect,
app.use("/hwhelp", (req, res) => {
res.redirect("/");
});
app.get('/links', (req, res) => {
const domain = req.query.domain;
res.sendStatus(200);
});
//search queries
app.get("/api/search=:query", async (req, res) => {
const { query } = req.params;
const reply = await fetch(`http://api.duckduckgo.com/ac?q=${query}&format=json`).then((resp) => resp.json());
res.send(reply);
});
// copy and paste for more, but put it before this line
app.use(express.static("./public", {
extensions: ['html']
}));
// bar
server.on("request", (req, res) => {
if (bare.shouldRoute(req)) {
bare.routeRequest(req, res);
} else {
app(req, res);
}
});
server.on("upgrade", (req, socket, head) => {
if (bare.shouldRoute(req)) {
bare.routeUpgrade(req, socket, head);
} else {
socket.end();
}
});
server.listen({ port: PORT }, () => {});
server.on("listening", () => {
console.log("Hosting On http://localhost:8080");
});