SSL Certs for ElysiaJS and Bun

309 Views Asked by At

I am trying to setup an elysiaJS API on my own digital ocean droplet but im running into issues with setting up an SSL certificate. I can't find anything in the documentation for it and I tried taking a Node + Express approach but that method doesn't work for Elysia as far as I know.

looked something like this

const app = new Elysia();
... my elysia API

const httpsServer = https.createServer({
    key: fs.readFileSync('/etc/letsencrypt/live/myurl.com/privkey.pem'),
    cert: fs.readFileSync('/etc/letsencrypt/live/myurl.com/fullchain.pem')
  }, app.callback()); // CALL BACK DOESNT EXIST IN ELYSIA 
  
  httpsServer.listen(8080, () => {
    console.log('HTTPS Server running on port 8080');
  });

If anyone has any suggestions please let me know!

Tried to set up SSL certs with Bun + Elysia using a Node Express approach but that didn't work. Can't find anything on SSL with Elysia.

2

There are 2 best solutions below

0
theRealestAEP On

I figured out a nice solution.

If you just use bun.serve and app.handle - it works perfectly.

Bun.serve({
    port: 8080,
    fetch: (request) => {
        return app.handle(request) // this is the elysiaJS app
    },
    tls: {
        key: fs.readFileSync('/etc/letsencrypt/live/myurl.com/privkey.pem'),
        cert: fs.readFileSync('/etc/letsencrypt/live/myurl.com/fullchain.pem') //should probably use bun to read the file too
    },
});
1
Viany Manuel On

I'm currently using [email protected], and as far as I could tell (even from previous versions), you could use:

app.listen({
  port: 3000,
  tls: {
    key: Bun.file(join(import.meta.dir, "../key.pem")),
    cert: Bun.file(join(import.meta.dir, "../cert.pem")),
  },
  hostname: "0.0.0.0",
});

Edit: I forgot to add the hostname xD