When deploying nextjs app to c-panel
hosting it asks for entry point of the application which default is app.js
. In normal react application it's totally in control but when using nextjs
it's not clear which js file is resposible to fire-up the application.
any idea on picking right js file as application entry point?
EDIT:
My hosting provider provided me with following code to setup an express app (which uses next's request handler) to handle the request:
const express = require('express');
const next = require('next');
const dev = process.env.NODE_ENV !== 'production';
const nextApp = next({ dev });
const handle = nextApp.getRequestHandler();
const port = 3454;
nextApp.prepare().then(() => {
const app = express();
app.get('*', (req, res) => {
return handle(req, res);
});
app.listen(port, err => {
if (err) throw err;
console.log(`> Ready on localhost:${port}`);
});
});
it works but it's slow because it compiles source files on demand to server requests.
Next.js
has many entry points, actually eachNext.js
page is an entry point. What it the usage of thisc-panel
– Pathogenicnpm run build
(which will runnext build
, prepare a production build) and then give your custom express server entry pointserver.js
– Pathogenicindex.js
which i've selected as application startup file.so i think there most be such thing built intonextjs
itself which should be responsible to listen for requests and handle responses using production ready files not source files. – Morgun