question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to load custom configuration on NextJS custom server

See original GitHub issue

I’m trying to load my configuration to my custom server setup and this is not shown in the examples of mentioned in the documentation.

I have this file, where I load all the plugins with compose:

const withPlugins = require('next-compose-plugins')
const withEnv = require('next-env')
const withSass = require('@zeit/next-sass')
const withImages = require('next-images')
const withOptimizedImages = require('next-optimized-images')
const withSourceMaps = require('@zeit/next-source-maps')

const config = require('./config')

module.exports = withPlugins([
  withEnv(config.env),
  withImages(),
  [withSass, config.sass],
  [withOptimizedImages, config.optimizedImages],
  withSourceMaps(),
], config.next)

And this is my server configuration:

const express = require('express')
const next = require('next')
const helmet = require('helmet')
const routes = require('./config').routes
const conf = require('./next.config')

const port = process.env.PORT || 3000
const dev = process.env.NODE_ENV === 'development'
const app = next({ dev, dir: './src', conf: conf() })
const handler = routes.getRequestHandler(app)

app.prepare().then(() => {
  express()
    .use(helmet())
    .use(handler)
    .listen(port, (err) => {
      if (err) {
        throw err
      }

      console.log(`> Ready on http://localhost:${port}`) // eslint-disable-line no-console
    })
})

The server configuration only loads the NextJS configuration object using the conf option, but does not load the compose with plugins if I pass it.

Is there a way of using the plugins with my custom server all together?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

18reactions
timneutkenscommented, Aug 10, 2019

Going to close this as it doesn’t follow the issue template. Questions should be asked on https://spectrum.chat/next-js.

0reactions
balazsorban44commented, Jan 29, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Features: Custom Server
Start a Next.js app programmatically using a custom server. ... The custom server uses the following import to connect the server with the...
Read more >
How to load custom configuration on NextJS custom server
I'm trying to load my configuration to my custom server setup and this is not shown in the examples of mentioned in the...
Read more >
NextJS Custom Server - Handbook
Setup in new project ... Follow these steps to configure our custom NextJS server in your NextJS project: 1. Add a server.ts file...
Read more >
Customize your Next.JS App using next.config.js ... - YouTube
In this video, we will see how we can use the next. config.js file in our Next.JS applications to take our App to...
Read more >
Set Up Next.js with a Custom Express Server + Typescript
Let's go production · build:server : Build server code to dist directory · build:next : Build the Next.js application · build : Run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found