From 246debe642604bfbc304a38a1f4d4dd708816909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Broks=20Randolfs=20Gail=C4=ABtis?= Date: Wed, 5 Mar 2025 21:47:45 +0200 Subject: [PATCH] Use certs to serve https --- .env | 2 ++ apps/blakus-api/src/main.ts | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..384eb1b --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +API_HOST=192.168.0.155 +API_PORT=3000 \ No newline at end of file diff --git a/apps/blakus-api/src/main.ts b/apps/blakus-api/src/main.ts index 1332901..1b97734 100644 --- a/apps/blakus-api/src/main.ts +++ b/apps/blakus-api/src/main.ts @@ -1,12 +1,18 @@ import Fastify from 'fastify'; +import fs from 'fs'; +import path from 'path'; import { app } from './app/app'; -const host = process.env.HOST ?? 'localhost'; -const port = process.env.PORT ? Number(process.env.PORT) : 3000; +const host = process.env.API_HOST ?? 'localhost'; +const port = process.env.API_PORT ? Number(process.env.API_PORT) : 3000; // Instantiate Fastify with some config const server = Fastify({ logger: true, + https: { + key: fs.readFileSync(path.join(__dirname, '..', 'certs', 'key.pem')), + cert: fs.readFileSync(path.join(__dirname, '..', 'certs', 'cert.pem')), + } }); // Register your application as a normal plugin. @@ -18,6 +24,6 @@ server.listen({ port, host }, (err) => { server.log.error(err); process.exit(1); } else { - console.log(`[ ready ] http://${host}:${port}`); + console.log(`[ ready ] https://${host}:${port}`); } });