/**
 * Plesk Node.js Manager Entry Point (Phusion Passenger)
 * Starts Next.js production server for porwoll.de
 */

const { createServer } = require("http")
const { parse } = require("url")
const next = require("next")

const port = parseInt(process.env.PORT || "3000", 10)
const dev = process.env.NODE_ENV !== "production"
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
  createServer((req, res) => {
    const parsedUrl = parse(req.url, true)
    handle(req, res, parsedUrl)
  }).listen(port, "0.0.0.0", (err) => {
    if (err) throw err
    console.log(`Next.js server ready on http://0.0.0.0:${port}`)
    console.log(`Environment: ${process.env.NODE_ENV}`)
    console.log(`Site: porwoll.de`)
  })
})
