Next.js: Allow for starting local server for next export

Created on 8 May 2018  路  4Comments  路  Source: vercel/next.js

My application is using local GraphQL API for rendering SSR content. It communicates to it on http://localhost:3000/graphql endpoint and this endpoint is served with custom next.js server. Now when I run next export, the export fails because this server is not running.

Is there a way to start http server for the duration of next export?

Most helpful comment

It's not as easy as it sounds so startup, synchronize and shutdown both. Ideally next export would allow to specify script to start custom server instead of starting server on its own. This way exports would also be 1:1 to what's configured in custom server setup (e.g. I use middlewares to inject some variables). Please consider.

All 4 comments

I guess you can just use a module like https://www.npmjs.com/package/concurrently 馃

It's not as easy as it sounds so startup, synchronize and shutdown both. Ideally next export would allow to specify script to start custom server instead of starting server on its own. This way exports would also be 1:1 to what's configured in custom server setup (e.g. I use middlewares to inject some variables). Please consider.

I am running into the same problem. I have an endpoint next export needs to query the data to hydrate all the things. Everything works well until I try to export and it says "oh that endpoint we've been playing nice with this whole time? ... lol, sike!".

I agree with @sheerun, Concurrently is not ideal.

Potentially we could introduce a programmatic api for next export, however you'd still run into issues as getInitialProps is called when switching pages even when there has been a static export. We also recommend not having the api combined with the Next.js server. Feel free to open up an RFC speccing out programmatic access to next export.

Was this page helpful?
0 / 5 - 0 ratings