refactor: Centralize Socket.IO client options in config for improved maintainability and consistency across prerender scripts
This commit is contained in:
@@ -66,12 +66,7 @@ const renderSingleProduct = async (productSeoName) => {
|
|||||||
const socketUrl = "http://127.0.0.1:9303";
|
const socketUrl = "http://127.0.0.1:9303";
|
||||||
console.log(`🔌 Connecting to socket at ${socketUrl}...`);
|
console.log(`🔌 Connecting to socket at ${socketUrl}...`);
|
||||||
|
|
||||||
const socket = io(socketUrl, {
|
const socket = io(socketUrl, config.socketIoClientOptions);
|
||||||
path: "/socket.io/",
|
|
||||||
transports: ["websocket"],
|
|
||||||
reconnection: false,
|
|
||||||
timeout: 10000,
|
|
||||||
});
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
|
|||||||
@@ -166,12 +166,7 @@ const NotFound404 = require("./src/pages/NotFound404.js").default;
|
|||||||
// Worker function for parallel product rendering
|
// Worker function for parallel product rendering
|
||||||
const renderProductWorker = async (productSeoNames, workerId, progressCallback, categoryMap = {}) => {
|
const renderProductWorker = async (productSeoNames, workerId, progressCallback, categoryMap = {}) => {
|
||||||
const socketUrl = "http://127.0.0.1:9303";
|
const socketUrl = "http://127.0.0.1:9303";
|
||||||
const workerSocket = io(socketUrl, {
|
const workerSocket = io(socketUrl, config.socketIoClientOptions);
|
||||||
path: "/socket.io/",
|
|
||||||
transports: ["websocket"],
|
|
||||||
reconnection: false,
|
|
||||||
timeout: 10000,
|
|
||||||
});
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
let processedCount = 0;
|
let processedCount = 0;
|
||||||
@@ -863,12 +858,7 @@ const fetchCategoryDataAndRender = () => {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}, 15000);
|
}, 15000);
|
||||||
|
|
||||||
const socket = io(socketUrl, {
|
const socket = io(socketUrl, config.socketIoClientOptions);
|
||||||
path: "/socket.io/",
|
|
||||||
transports: ["websocket"],
|
|
||||||
reconnection: false,
|
|
||||||
timeout: 10000,
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on("connect", () => {
|
socket.on("connect", () => {
|
||||||
console.log('Socket connected. Emitting "categoryList"...');
|
console.log('Socket connected. Emitting "categoryList"...');
|
||||||
|
|||||||
@@ -69,11 +69,21 @@ const globalCssCollection = new Set();
|
|||||||
// Get webpack entrypoints
|
// Get webpack entrypoints
|
||||||
const webpackEntrypoints = getWebpackEntrypoints();
|
const webpackEntrypoints = getWebpackEntrypoints();
|
||||||
|
|
||||||
|
/** Socket.IO client options for prerender scripts: skip backend connection counters (balanced on disconnect). */
|
||||||
|
const socketIoClientOptions = {
|
||||||
|
path: "/socket.io/",
|
||||||
|
transports: ["websocket"],
|
||||||
|
reconnection: false,
|
||||||
|
timeout: 10000,
|
||||||
|
auth: { prerender: true },
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
isProduction,
|
isProduction,
|
||||||
outputDir,
|
outputDir,
|
||||||
getWebpackEntrypoints,
|
getWebpackEntrypoints,
|
||||||
globalCss,
|
globalCss,
|
||||||
globalCssCollection,
|
globalCssCollection,
|
||||||
webpackEntrypoints
|
webpackEntrypoints,
|
||||||
|
socketIoClientOptions,
|
||||||
};
|
};
|
||||||
@@ -42,6 +42,7 @@ const fetchCategoryProducts = (socket, categoryId) => {
|
|||||||
"getCategoryProducts",
|
"getCategoryProducts",
|
||||||
{
|
{
|
||||||
full: true,
|
full: true,
|
||||||
|
nocount: true,
|
||||||
categoryId:
|
categoryId:
|
||||||
categoryId === "neu" || categoryId === "bald"
|
categoryId === "neu" || categoryId === "bald"
|
||||||
? categoryId
|
? categoryId
|
||||||
|
|||||||
Reference in New Issue
Block a user