-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
60 lines (47 loc) · 1.39 KB
/
server.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
const path = require("path");
const axios = require('axios');
const fastify = require("fastify")({
logger: false,
});
// https://t.me/rmsup | @secbaz
// Setup our static files
fastify.register(require("@fastify/static"), {
root: path.join(__dirname, "public"),
prefix: "/", // optional: default '/'
});
// Formbody lets us parse incoming forms
fastify.register(require("@fastify/formbody"));
// View is a templating manager for fastify
fastify.register(require("@fastify/view"), {
engine: {
handlebars: require("handlebars"),
},
});
// Load and parse SEO data
const seo = require("./src/seo.json");
if (seo.url === "glitch-default") {
seo.url = `https://${process.env.PROJECT_DOMAIN}.glitch.me`;
}
fastify.get("/", function (request, reply) {
return "404 Page Not found.";
});
fastify.post("/", async function (request, reply) {
const payload = request.body;
try {
const response = await axios.post(`https://api.telegram.org/bot${payload.token}/${payload.method}`, payload.data);
return response.data;
} catch (error) {
return { error: error };
}
});
// https://t.me/rmsup | @secbaz
fastify.listen(
{ port: process.env.PORT, host: "0.0.0.0" },
function (err, address) {
if (err) {
console.error(err);
process.exit(1);
}
console.log(`Your app is listening on ${address}`);
}
);