@nx/next
Version:
38 lines (37 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = serveExecutor;
const devkit_1 = require("@nx/devkit");
const path_1 = require("path");
async function* serveExecutor(options, context) {
// Cast to any to overwrite NODE_ENV
process.env.NODE_ENV = process.env.NODE_ENV
? process.env.NODE_ENV
: options.dev
? 'development'
: 'production';
// Setting port that the custom server should use.
process.env.PORT = options.port ? `${options.port}` : process.env.PORT;
options.port = parseInt(process.env.PORT);
const projectRoot = context.projectGraph.nodes[context.projectName].data.root;
yield* runCustomServer(projectRoot, options, context);
}
async function* runCustomServer(root, options, context) {
process.env.NX_NEXT_DIR ??= root;
process.env.NX_NEXT_PUBLIC_DIR = (0, path_1.join)(root, 'public');
const httpProtocol = options.customServerHttps ? 'https' : 'http';
const baseUrl = `${httpProtocol}://${options.hostname || 'localhost'}:${options.port}`;
const customServerBuild = await (0, devkit_1.runExecutor)((0, devkit_1.parseTargetString)(options.customServerTarget, context), {
watch: options.dev ? true : false,
}, context);
for await (const result of customServerBuild) {
if (!result.success) {
return result;
}
yield {
success: true,
baseUrl,
};
}
return { success: true };
}