Skip to content

Commit

Permalink
faststore-poc(SFS-1709): test custom server
Browse files Browse the repository at this point in the history
  • Loading branch information
biancasilvavtex committed Oct 31, 2024
1 parent 7ca9614 commit be06674
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions packages/core/server.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
const http = require('http')
const url = require('url')
const NextServer = require('next/dist/server/next-server').default
const { config } = require('./.next/required-server-files.json')
const { parse } = require('url')

// eslint-disable-next-line turbo/no-undeclared-env-vars
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(config)
const next = require('next')

// eslint-disable-next-line turbo/no-undeclared-env-vars
const port = parseInt(process.env.PORT || '3000', 10)
// eslint-disable-next-line turbo/no-undeclared-env-vars
const hostname = process.env.HOSTNAME || 'localhost'
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

const app = new NextServer({
hostname: hostname,
port,
dir: process.cwd(),
dev,
conf: config,
})
const { config } = require('./.next/required-server-files.json')

const handle = app.getRequestHandler()
// eslint-disable-next-line turbo/no-undeclared-env-vars
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(config)

app.prepare().then(() => {
http
.createServer((req, res) => {
let startTime = Date.now()
const parsedUrl = parse(req.url, true)
const parsedUrl = url.parse(req.url, true)
handle(req, res, parsedUrl).then(() => {
let startTime = Date.now()
console.log({
url: req.url,
method: req.method,
Expand All @@ -39,11 +29,11 @@ app.prepare().then(() => {
})
})
})
.listen(port, () => {
console.log(
`> [CUSTOM] Server listening at http://${hostname}:${port} as ${
dev ? 'development' : process.env.NODE_ENV
}`
)
})
.listen(port)

console.log(
`> Server listening at http://localhost:${port} as ${
dev ? 'development' : process.env.NODE_ENV
}`
)
})

0 comments on commit be06674

Please sign in to comment.