Skip to content

Commit 75a8df4

Browse files
author
Cihan SELİM
committed
ADD fullComponentPath to render multiple, minor changes in serverjs & webpack
1 parent acb1752 commit 75a8df4

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/renderMultiple.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ function getRenderer(name, req) {
4040

4141
if (routeInfo) {
4242
const urlWithPath = url.replace('/', path);
43+
const fullComponentPath = `/components/${req.params.components ?? ''}`;
4344

4445
const context = {
4546
path,
4647
query,
4748
cookies,
4849
url: urlWithPath,
4950
userAgent,
50-
componentPath,
51+
componentPath: fullComponentPath,
5152
...renderOptions
5253
};
5354

@@ -207,6 +208,7 @@ async function getResponses(renderers) {
207208
async function getPreview(responses, requestCount, req) {
208209
const layoutName = getPreviewLayout(req.query);
209210
const { layouts = {} } = previewPages?.default || {};
211+
const componentNames = Object.keys(responses);
210212
let PreviewFile = Preview;
211213

212214
if (layouts[layoutName]) {
@@ -218,7 +220,7 @@ async function getPreview(responses, requestCount, req) {
218220
return getLayoutWithClass(componentName, responses[name].fullHtml);
219221
});
220222

221-
return PreviewFile([...content].join('\n'), `${requestCount} request!`);
223+
return PreviewFile([...content].join('\n'), `${requestCount} request!`, componentNames);
222224
}
223225

224226
const DEFAULT_PARTIALS = ['RequestDispatcher'];

src/server.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import http from 'http';
33
import voltranConfig from '../voltran.config';
44
import { hiddie, composedMiddlewares, prepareMiddlewares } from './middleware';
55

6+
const isDebug = voltranConfig.dev;
7+
const customServer = voltranConfig.entry.server;
8+
const canStartServer = process.env.NODE_ENV === 'production' && (!customServer || isDebug);
9+
610
const launchServer = () => {
711
prepareMiddlewares();
812
http.createServer(hiddie.run).listen(voltranConfig.port);
913
};
1014

11-
if (process.env.NODE_ENV === 'production' && !voltranConfig.entry.server) {
15+
if (canStartServer) {
1216
launchServer();
1317
}
1418

webpack.server.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const voltranServerConfigPath = voltranConfig.webpackConfiguration.server;
2525
const voltranServerConfig = voltranServerConfigPath
2626
? require(voltranConfig.webpackConfiguration.server)
2727
: '';
28-
const voltranCustomServer = voltranConfig.entry.server || 'src/server.js';
28+
const voltranCustomServer =
29+
voltranConfig.entry.server && !isDebug ? voltranConfig.entry.server : 'src/server.js';
2930

3031
const voltranServer = path.resolve(__dirname, isDebug ? voltranCustomServer : 'src/main.js');
3132

0 commit comments

Comments
 (0)