Skip to content

Commit 6482ec9

Browse files
author
ahmetkuslular
committed
FIX code review issues
1 parent f6a2827 commit 6482ec9

File tree

14 files changed

+74
-104
lines changed

14 files changed

+74
-104
lines changed

config/emptyModule.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

config/string.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ function replaceString() {
3333
},
3434
{
3535
search: '__V_REQUEST_CONFIGS__',
36-
replace: normalizeUrl(voltranConfig.routing.requestConfigs),
36+
replace: normalizeUrl(
37+
voltranConfig.routing.requestConfigs || path.resolve(__dirname, './emptyModule.js')
38+
),
3739
flags: 'g'
3840
},
3941
{
4042
search: '__V_PREVIEW_PAGES__',
41-
replace: normalizeUrl(voltranConfig.routing.previewPages),
43+
replace: normalizeUrl(
44+
voltranConfig.routing.previewPages || path.resolve(__dirname, './emptyModule.js')
45+
),
4246
flags: 'g'
4347
},
4448
{

jest.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Jest configuration
2-
// https://facebook.github.io/jest/docs/en/configuration.html
31
module.exports = {
42
verbose: true,
53
automock: false,
@@ -11,6 +9,11 @@ module.exports = {
119
'!src/public/**',
1210
'!src/tools/**'
1311
],
12+
env: {
13+
production: {
14+
plugins: ['transform-es2015-modules-commonjs']
15+
}
16+
},
1417
coverageDirectory: '<rootDir>/coverage',
1518
globals: {
1619
window: true,

lib/os.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
const path = require('path');
22

33
function normalizeUrl(url) {
4-
const urlArray = url.split(path.sep);
5-
6-
return urlArray.join('/');
4+
if (url) {
5+
const urlArray = url?.split(path.sep);
6+
7+
return urlArray.join('/');
8+
}
9+
10+
return '';
711
}
812

9-
module.exports = normalizeUrl;
13+
module.exports = normalizeUrl;

src/render.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import xss from 'xss';
22

33
import { matchUrlInRouteConfigs } from './universal/core/route/routeUtils';
44
import Preview from './universal/components/Preview';
5-
import { HTTP_STATUS_CODES } from './universal/utils/constants';
5+
import { BLACKLIST_OUTPUT, HTTP_STATUS_CODES } from './universal/utils/constants';
66
import metrics from './metrics';
77
import {
88
renderComponent,
@@ -13,6 +13,7 @@ import {
1313
} from './universal/service/RenderService';
1414
import Component from './universal/model/Component';
1515
import logger from './universal/utils/logger';
16+
import omit from 'lodash/omit';
1617

1718
const appConfig = require('__APP_CONFIG__');
1819

@@ -60,9 +61,9 @@ const render = async (req, res) => {
6061
scripts,
6162
activeComponent,
6263
componentName,
63-
seoState,
6464
isPreviewQuery,
65-
responseOptions
65+
responseOptions,
66+
...responseData
6667
} = renderResponse;
6768

6869
const statusCode = responseOptions?.isPartialContent
@@ -71,8 +72,8 @@ const render = async (req, res) => {
7172

7273
if (!isPreview(context.query)) {
7374
const html = renderLinksAndScripts(output, '', '');
74-
75-
res.status(statusCode).json({ html, scripts, style: links, activeComponent, seoState });
75+
const otherParams = omit(responseData, BLACKLIST_OUTPUT);
76+
res.status(statusCode).json({ html, scripts, style: links, activeComponent, ...otherParams });
7677

7778
metrics.fragmentRequestDurationMicroseconds
7879
.labels(componentName, isWithoutHTML(context.query) ? '1' : '0')

src/renderMultiple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async function getResponses(renderers) {
201201

202202
async function getPreview(responses, requestCount, req) {
203203
const layoutName = getPreviewLayout(req.query);
204-
const { layouts } = previewPages.default;
204+
const { layouts = {} } = previewPages?.default || {};
205205
let PreviewFile = Preview;
206206

207207
if (layouts[layoutName]) {

src/universal/components/RequestDispatcher/RequestDispatcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { isExitCondition } from './RequestDispatcher.utils';
66

77
const requestConfigs = require('__V_REQUEST_CONFIGS__');
88

9-
const { effects = [] } = requestConfigs.default;
9+
const { effects = [] } = requestConfigs?.default || {};
1010
const requestPrefix = 'RequestDispatcher.';
1111
const responsePrefix = 'RequestDispatcher.Response.';
1212

src/universal/model/Renderer.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import omit from 'lodash/omit';
22
import { isPreview, renderComponent, renderLinksAndScripts } from '../service/RenderService';
3+
import { BLACKLIST_OUTPUT } from '../utils/constants';
34

4-
const blacklistOutput = [
5-
'componentName',
6-
'fullWidth',
7-
'isMobileComponent',
8-
'isPreviewQuery',
9-
'responseOptions'
10-
];
115
export default class Renderer {
126
constructor(component, context) {
137
this.component = component;
@@ -47,7 +41,7 @@ export default class Renderer {
4741
return new Promise(resolve => {
4842
renderComponent(this.component, this.context, this.initialState).then(response => {
4943
const { output, links, fullHtml, ...rest } = response;
50-
const otherParams = omit(rest, blacklistOutput);
44+
const otherParams = omit(rest, BLACKLIST_OUTPUT);
5145
const html = renderLinksAndScripts(output, '', '');
5246

5347
resolve({

src/universal/partials/Welcome/PartialList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const Welcome = () => {
1616
<Link href={item.previewUrl ? item.previewUrl : `${item.url}?preview`} target="_blank">
1717
<Name>{item.name}</Name>
1818
<Url>{item.url}</Url>
19-
<Footer>
19+
<Footer status={item.status}>
2020
<Label status={item.status}>
2121
{item.status} <Dot status={item.status} />
2222
</Label>

src/universal/partials/Welcome/partials.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import components from '../../core/route/components';
33
const previewPages = require('__V_PREVIEW_PAGES__');
44

55
const partials = [];
6-
6+
const BLACKLIST = ['REQUEST_DISPATCHER'];
77
Object.keys(components).forEach(path => {
88
const info = components[path];
9-
partials.push({
10-
name: info.fragmentName,
11-
url: path,
12-
status: info.status
13-
});
9+
if (!BLACKLIST.includes(info.name)) {
10+
partials.push({
11+
name: info.fragmentName,
12+
url: path,
13+
status: info.status
14+
});
15+
}
1416
});
15-
partials.push(...previewPages.default.pages);
17+
const pages = previewPages?.default?.pages || [];
18+
partials.push(...pages);
1619

1720
export default partials;

0 commit comments

Comments
 (0)