Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs): update custom server setup so hostname and port are alwa… #10103

Merged
merged 1 commit into from
May 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,67 +57,5 @@ export function createNextServerFiles(host: Tree, options: NormalizedSchema) {
}
`
);

const { appsDir } = getWorkspaceLayout(host);

host.write(
joinPathFragments(directory, 'server.js'),
`
// @ts-check
'use strict';
/**
* Production Nextjs custom server
*
* Usage: run this script with node
* Adjust dir option for your serve/deploy config
*
* node server.js
*/
/**
* @typedef {import(${
isOldNext
? 'next/dist/next-server/server/next-server'
: 'next/dist/server/next-server'
}).default} Server
*/
const NextServer = require(${
isOldNext
? 'next/dist/next-server/server/next-server'
: 'next/dist/server/next-server'
}).default;
const express = require('express');
const nextApp = new NextServer({
dir: './dist/${appsDir}/<%= name %>',
staticMarkup: false,
quiet: false,
conf: {
distDir: '.'
}
});
const serve = async () => {
const handle = nextApp.getRequestHandler();
const expressApp = express();
await nextApp.prepare();
return new Promise((resolve, reject) => {
expressApp.all('*', (req, res) => {
return handle(req, res);
});
const server = expressApp.listen(4200, err => {
err ? reject(err) : resolve(server);
});
});
}
serve().then(server => console.log('Server is running on port 4200'));
`
);
}
}