Replies: 8 comments 14 replies
-
Hello. What is the |
Beta Was this translation helpful? Give feedback.
-
I was about to open same topic. I am using custom server similar to official example, will https://github.com/vercel/next.js/tree/canary/examples/custom-server-typescript |
Beta Was this translation helpful? Give feedback.
-
@blackmann did you ever figure this out? I'm guessing you may have to just copy your server into the standalone directory manually? |
Beta Was this translation helpful? Give feedback.
-
I tried to do this, but my problem was that the output file tracer throws out a lot of files from standalone/node_modules/next, including dist/server/next.js, but without this file it's very difficult to set up a custom server. |
Beta Was this translation helpful? Give feedback.
-
Perhaps one option is to set up a script or run a set of commands to insert and replace the contents of a ready-made server.js file into the server.js file that gets built in the standalone directory.
I'm going to try something similar, but using sed in order to append a few extra lines to the built server.js file. I reckon I'll run this on every deployment as part of the dockerfile (the plan is to dockerize our app). |
Beta Was this translation helpful? Give feedback.
-
I also encountered the same problem, is there any solution? |
Beta Was this translation helpful? Give feedback.
-
To get a custom server running with
Alternatively, you could bundle your server file (like @sadg mentioned). So the
|
Beta Was this translation helpful? Give feedback.
-
I am in the same situation with a custom server using depedencies My server.js looks like this const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')
const { getServerUrl } = require('./utils/get-server-url')
const { logger } = require('./utils/logger')
const { connectAzureBus, injectKeyVaultValues, connectAppInsights } = require('./helpers/azure')
const { startRevalidation } = require('./app/api/webhook/revalidate/start')
switch (process.env.npm_lifecycle_event) {
case 'start':
process.env.NODE_ENV = 'production'
break
case 'dev':
process.env.NODE_ENV = 'development'
break
default:
logger.error(`${process.env.npm_lifecycle_event} does not exist`)
}
const { hostname, port, dev } = getServerUrl()
if (!dev) {
const { config } = require('./.next/required-server-files.json')
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(config)
}
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()
app
.prepare()
.then(async () => {
await injectKeyVaultValues()
})
.then(() => {
createServer(async (req, res) => {
const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl)
}).listen(port, (err) => {
if (err) throw err
logger.info(`APP_START ${process.env.NEXT_PUBLIC_APP_URL}`)
if (!dev) {
connectAppInsights()
connectAzureBus().catch((error) => {
logger.error(error)
process.exit(1)
})
if (process.env.npm_config_clear) {
startRevalidation()
}
}
})
}) First I noticed my module.exports = ({
output: 'standalone',
experimental: {
outputFileTracingIncludes: {
'/': [
'./utils/**/*',
'./helpers/**/*',
'./app/api/webhook/revalidate/start.js'
]},
}, This is working but since I am using some package for azure such as example : ....
COPY --from=builder /app/node_modules/winston ./node_modules/winston
COPY --from=builder /app/node_modules/@colors/colors ./node_modules/@colors/colors
COPY --from=builder /app/node_modules/@dabh/diagnostics ./node_modules/@dabh/diagnostics
COPY --from=builder /app/node_modules/async ./node_modules/async
COPY --from=builder /app/node_modules/is-stream ./node_modules/is-stream
COPY --from=builder /app/node_modules/logform ./node_modules/logform
COPY --from=builder /app/node_modules/one-time ./node_modules/one-time
COPY --from=builder /app/node_modules/readable-stream ./node_modules/readable-stream
COPY --from=builder /app/node_modules/safe-stable-stringify ./node_modules/safe-stable-stringify
COPY --from=builder /app/node_modules/stack-trace ./node_modules/stack-trace
COPY --from=builder /app/node_modules/triple-beam ./node_modules/triple-beam
COPY --from=builder /app/node_modules/winston-transport ./node_modules/winston-transport
... I had to dot this for each dependency of my server.js file. This is boring... |
Beta Was this translation helpful? Give feedback.
-
How to setup experimental
outputStandalone
with customserver.js
? It appears, the server.js included in the build is what comes from nextjs and not mine.Beta Was this translation helpful? Give feedback.
All reactions