From 75a8df4c6eee0a71825f76d3398edacee764adf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20SEL=C4=B0M?= Date: Wed, 20 Apr 2022 09:52:47 +0300 Subject: [PATCH] ADD fullComponentPath to render multiple, minor changes in serverjs & webpack --- src/renderMultiple.js | 6 ++++-- src/server.js | 6 +++++- webpack.server.config.js | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/renderMultiple.js b/src/renderMultiple.js index fd89137..92f21b1 100644 --- a/src/renderMultiple.js +++ b/src/renderMultiple.js @@ -40,6 +40,7 @@ function getRenderer(name, req) { if (routeInfo) { const urlWithPath = url.replace('/', path); + const fullComponentPath = `/components/${req.params.components ?? ''}`; const context = { path, @@ -47,7 +48,7 @@ function getRenderer(name, req) { cookies, url: urlWithPath, userAgent, - componentPath, + componentPath: fullComponentPath, ...renderOptions }; @@ -207,6 +208,7 @@ async function getResponses(renderers) { async function getPreview(responses, requestCount, req) { const layoutName = getPreviewLayout(req.query); const { layouts = {} } = previewPages?.default || {}; + const componentNames = Object.keys(responses); let PreviewFile = Preview; if (layouts[layoutName]) { @@ -218,7 +220,7 @@ async function getPreview(responses, requestCount, req) { return getLayoutWithClass(componentName, responses[name].fullHtml); }); - return PreviewFile([...content].join('\n'), `${requestCount} request!`); + return PreviewFile([...content].join('\n'), `${requestCount} request!`, componentNames); } const DEFAULT_PARTIALS = ['RequestDispatcher']; diff --git a/src/server.js b/src/server.js index e1483e1..2c653fc 100644 --- a/src/server.js +++ b/src/server.js @@ -3,12 +3,16 @@ import http from 'http'; import voltranConfig from '../voltran.config'; import { hiddie, composedMiddlewares, prepareMiddlewares } from './middleware'; +const isDebug = voltranConfig.dev; +const customServer = voltranConfig.entry.server; +const canStartServer = process.env.NODE_ENV === 'production' && (!customServer || isDebug); + const launchServer = () => { prepareMiddlewares(); http.createServer(hiddie.run).listen(voltranConfig.port); }; -if (process.env.NODE_ENV === 'production' && !voltranConfig.entry.server) { +if (canStartServer) { launchServer(); } diff --git a/webpack.server.config.js b/webpack.server.config.js index 7a401ca..ba036dc 100644 --- a/webpack.server.config.js +++ b/webpack.server.config.js @@ -25,7 +25,8 @@ const voltranServerConfigPath = voltranConfig.webpackConfiguration.server; const voltranServerConfig = voltranServerConfigPath ? require(voltranConfig.webpackConfiguration.server) : ''; -const voltranCustomServer = voltranConfig.entry.server || 'src/server.js'; +const voltranCustomServer = + voltranConfig.entry.server && !isDebug ? voltranConfig.entry.server : 'src/server.js'; const voltranServer = path.resolve(__dirname, isDebug ? voltranCustomServer : 'src/main.js');