From 9bae551e82ab7ea46c7750774d0f5a9df0249871 Mon Sep 17 00:00:00 2001 From: SivertEikrem Date: Wed, 25 Nov 2026 13:38:44 +0100 Subject: [PATCH] Close port 3001 from outside the VM (#109) --- backend/src/server.ts | 8 +++++--- docs/vm.md | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/server.ts b/backend/src/server.ts index 3f707f2..a219fea 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -9,6 +9,8 @@ import { allResolvers, allTypeDefs } from './graphql'; const PORT = Number(process.env.PORT ?? 3001); +const HOST = '127.0.0.1'; + async function main() { const app = express(); // Each feature adds its own types and resolvers. See graphql.ts. @@ -39,9 +41,9 @@ async function main() { // SameSite=Lax cookie is not sent with cross-site POSTs. Together they protect the login cookie. app.use('/graphql', express.json(), expressMiddleware(apollo, { context: createContext })); - app.listen(PORT, () => { - console.log(`Backend listening on http://localhost:${PORT}`); - console.log(`GraphQL: http://localhost:${PORT}/graphql`); + app.listen(PORT, HOST, () => { + console.log(`Backend listening on http://${HOST}:${PORT}`); + console.log(`GraphQL: http://${HOST}:${PORT}/graphql`); }); } diff --git a/docs/vm.md b/docs/vm.md index 0427aad..56249a1 100644 --- a/docs/vm.md +++ b/docs/vm.md @@ -147,6 +147,7 @@ This is done once per VM. Steps 1 to 3 are done once for each person who deploys ## Apache Apache serves the built frontend and forwards `/project2/graphql` to the backend on port 3001. +The backend listens only on `127.0.0.1`, so port 3001 cannot be reached from outside the VM. The configuration is in `/etc/apache2/conf-available/project2.conf`: ```apache