Skip to content

Commit

Permalink
ADD fullComponentPath to render multiple, minor changes in serverjs &…
Browse files Browse the repository at this point in the history
… webpack
  • Loading branch information
Cihan SELİM committed Apr 20, 2022
1 parent acb1752 commit 75a8df4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/renderMultiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ function getRenderer(name, req) {

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

const context = {
path,
query,
cookies,
url: urlWithPath,
userAgent,
componentPath,
componentPath: fullComponentPath,
...renderOptions
};

Expand Down Expand Up @@ -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]) {
Expand All @@ -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'];
Expand Down
6 changes: 5 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
3 changes: 2 additions & 1 deletion webpack.server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 75a8df4

Please sign in to comment.