// Standalone Express app for server<->bot internal traffic. It is mounted on its
// OWN http listener (INTERNAL_PORT, default 3001) in server.js — an unpublished,
// compose-network-only port, mirroring how the bot exposes its internal API on
// 4100. Crucially it is NOT part of the public API app (app.js), so /internal/*
// (which returns the DECRYPTED Discord bot token) can never ride the same
// listener Pangolin proxies to the world. Shared-secret gated by
// requireInternalKey inside internal.routes. See issue #33.
const express = require('express')

const internalRouter = require('./router/v1/internal/internal.routes')

const internalApp = express()

// Internal-only listener, but don't advertise the stack anyway (defense in depth).
internalApp.disable('x-powered-by')

internalApp.use(express.json())

// Liveness probe for this listener (no secret required); mirrors the bot's
// /health on 4100. Useful for compose healthchecks without exposing anything.
internalApp.get('/health', (req, res) => res.json({ status: 'ok' }))

// requireInternalKey is applied inside internal.routes.
internalApp.use('/internal', internalRouter)

// Anything else on this listener is not a real internal route.
internalApp.use((req, res) => res.status(404).json({ message: 'Not found' }))

module.exports = internalApp
