I was developing a bot for Monkeys (an open source organisation focused on creating a no-nonsense information), to help with routine tasks, reminders etc.
The discord documentation recommends ngrok for hosting the bot server. So when I clicked on the site, and saw a signup page my mind shouted lame!.
What if there was a way to host my server but without having to rely on a cloud service that requires a signup. Spoiler alert! malai was just the answer I was looking for.
Malai is a tool that lets you expose your HTTP as well as TCP on internet via Kulfi network which is a P2P network, so no cloud!.
Let me demonstrate how easy it is to create host a discord bot server with malai, and test it.
I am using Deno. But you can follow any tech stack here.
Let’s add a healthcheck route and test if our server is hosted on internet or not.
main.js
import { Application, Router } from "@oak/oak";
const app = new Application();
const router = new Router();
router.get("/", (ctx) => {
ctx.response.body = "healthy";
});
app.use(router.routes());
app.listen({ port: 3000 })
I run this server on localhost using
Terminal window
deno main.js
Now to host this server with malai I just need to run one command i.e
Terminal window
malai http 3000 --public
Malai will generate a unique url that you can use and access your server from anywhere.
To confirm that we’re really on the internet, let’s create an endpoint which discord will use to register the bot.
router.post("/api", async (ctx, next) => {
// verify discord header and body
const { valid, body } = await verifySignature(ctx.request);
if (!valid) {
ctx.response.status = 400;
ctx.response.type = "application/json";
ctx.response.body = { message: "Hello, Oak!" };
return next();
}
if (body.type == 1) {
ctx.response.status = 200;
ctx.response.type = "application/json";
ctx.response.body = { type: 1 };
return next();
}
})
That’s it! Malai is so easy to use and there is no signup process, authentication tokens api limit. Just generate a unique url and use it. I built a whole discord bot using malai, you can find it’s code at https://github.com/the-monkeys/orangutan
Join Tanishq on Peerlist!
Join amazing folks like Tanishq and thousands of other people in tech.
Create ProfileJoin with Tanishq’s personal invite link.
0
9
0