Files
payloadcms/test/helpers/bootAdminPanel.mjs
German Jablonski cf427e5519 fix: imports (part 2/2) (#13520)
Completes https://github.com/payloadcms/payload/pull/13513

That PR fixed it for the `admin` suite, but I had also encountered the
same issue in `live-preview`.

When searching for instances, I found others with the same pattern
within packages, which I took the opportunity to fix in case the same
error occurs in the future.
2025-08-20 08:08:55 -04:00

36 lines
882 B
JavaScript

import { createServer } from 'http'
import next from 'next'
import { parse } from 'url'
const actualNext = 'default' in next ? next.default : next
export const bootAdminPanel = async ({ port = 3000, appDir }) => {
const serverURL = `http://localhost:${port}`
const app = actualNext({
dev: true,
hostname: 'localhost',
port,
dir: appDir,
})
const handle = app.getRequestHandler()
await app.prepare()
createServer(async (req, res) => {
try {
const parsedUrl = parse(req.url, true)
await handle(req, res, parsedUrl)
} catch (err) {
console.error('Error occurred handling', req.url, err)
res.statusCode = 500
res.end('internal server error')
}
})
.once('error', (err) => {
console.error(err)
process.exit(1)
})
.listen(port, () => {
console.log(`> Ready on ${serverURL}`)
})
}