import { createServer } from 'node:http'
import { handleAuthApiRequest } from './game-api.mjs'

process.env.NODE_ENV = process.env.NODE_ENV ?? 'production'
process.env.CORS_ORIGINS = process.env.CORS_ORIGINS
  ?? process.env.AUTH_CORS_ORIGINS
  ?? '*'

const host = process.env.AUTH_HOST ?? process.env.HOST ?? '127.0.0.1'
const port = Number(process.env.AUTH_PORT ?? process.env.PORT ?? 4174)

const server = createServer((request, response) => {
  handleAuthApiRequest(request, response)
})

server.listen(port, host, () => {
  console.log(`I want to Heal auth listening on http://${host}:${port}`)
})
