diff --git a/.eslintrc.js b/.eslintrc.js index 2a2f299..4febcfa 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -43,7 +43,9 @@ module.exports = { 'no-use-before-define': 'off', 'no-unused-expressions': 'off', 'no-nested-ternary': 'off', - 'no-underscore-dangle': 'off' + 'no-underscore-dangle': 'off', + 'consistent-return': 'off', + 'array-callback-return': 'off' }, env: { jest: true, diff --git a/src/client/client.js b/src/client/client.js index 32e7263..de5b90a 100644 --- a/src/client/client.js +++ b/src/client/client.js @@ -1,7 +1,7 @@ import 'whatwg-fetch'; import Eev from 'eev'; -"__V_styles__" +('__V_styles__'); if (!window.HbEventBus) { window.HbEventBus = new Eev(); diff --git a/src/index.js b/src/index.js index 1afd754..d534a79 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,6 @@ import withBaseComponent from './universal/partials/withBaseComponent'; import { SERVICES } from './universal/utils/constants'; export default { - withBaseComponent, - SERVICES, -}; \ No newline at end of file + withBaseComponent, + SERVICES +}; diff --git a/src/main.js b/src/main.js index 8a397fb..72af50c 100644 --- a/src/main.js +++ b/src/main.js @@ -20,7 +20,7 @@ if (cluster.isMaster) { cluster.fork(); }); - if (enablePrometheus){ + if (enablePrometheus) { const aggregatorRegistry = new prom.AggregatorRegistry(); const metricsPort = voltranConfig.port + 1; diff --git a/src/render.js b/src/render.js index 8a1d9ab..3f1f5ae 100644 --- a/src/render.js +++ b/src/render.js @@ -13,8 +13,11 @@ import { import Component from './universal/model/Component'; import logger from './universal/utils/logger'; +// eslint-disable-next-line consistent-return export default async (req, res) => { - const pathParts = xss(req.path).split('/').filter(part => part); + const pathParts = xss(req.path) + .split('/') + .filter(part => part); const componentPath = `/${pathParts.join('/')}`; const routeInfo = matchUrlInRouteConfigs(componentPath); @@ -26,8 +29,10 @@ export default async (req, res) => { path: xss(path), query: JSON.parse(xss(JSON.stringify(req.query))), cookies: xss(JSON.stringify(req.cookies)), - url: xss(req.url).replace(componentPath, '/').replace('//', '/'), - userAgent: xss(req.headers['user-agent']), + url: xss(req.url) + .replace(componentPath, '/') + .replace('//', '/'), + userAgent: xss(req.headers['user-agent']) }; const component = new Component(routeInfo.path); @@ -62,7 +67,7 @@ export default async (req, res) => { .labels(componentName, isWithoutHTML(context.query) ? '1' : '0') .observe(Date.now() - res.locals.startEpoch); } else { - res.html(Preview([fullHtml].join('\n'), [componentName])); + res.html(Preview([fullHtml].join('\n'))); } } else { res.status(HTTP_STATUS_CODES.NOT_FOUND).json({ diff --git a/src/renderMultiple.js b/src/renderMultiple.js index cb2861b..433094d 100644 --- a/src/renderMultiple.js +++ b/src/renderMultiple.js @@ -1,3 +1,4 @@ +/* eslint-disable no-param-reassign */ import { matchUrlInRouteConfigs } from './universal/core/route/routeUtils'; import Component from './universal/model/Component'; import Renderer from './universal/model/Renderer'; @@ -20,7 +21,7 @@ function getRenderer(name, query, cookies, url, path, userAgent) { query, cookies, url: urlWithPath, - userAgent, + userAgent }; if (Component.isExist(componentPath)) { @@ -173,7 +174,6 @@ async function getResponses(renderers) { async function getPreview(responses, requestCount) { return Preview( [...Object.keys(responses).map(name => responses[name].fullHtml)].join('\n'), - Object.keys(responses), `${requestCount} request!` ); } @@ -183,7 +183,16 @@ export default async (req, res) => { const renderers = req.params.components .split(',') .filter((value, index, self) => self.indexOf(value) === index) - .map(name => getRenderer(name, req.query, req.cookies, req.url, `/${req.params.path || ''}`, req.headers['user-agent'])) + .map(name => + getRenderer( + name, + req.query, + req.cookies, + req.url, + `/${req.params.path || ''}`, + req.headers['user-agent'] + ) + ) .filter(renderer => renderer != null); if (!renderers.length) { diff --git a/src/server.js b/src/server.js index debed5a..1381210 100644 --- a/src/server.js +++ b/src/server.js @@ -18,7 +18,7 @@ import render from './render'; import registerControllers from './api/controllers'; import renderMultiple from './renderMultiple'; - import { HTTP_STATUS_CODES } from './universal/utils/constants'; +import { HTTP_STATUS_CODES } from './universal/utils/constants'; import voltranConfig from '../voltran.config'; @@ -26,10 +26,11 @@ const enablePrometheus = voltranConfig.monitoring.prometheus; let Prometheus; if (enablePrometheus) { - Prometheus = require("__V_PROMETHEUS__"); + // eslint-disable-next-line global-require + Prometheus = require('__V_PROMETHEUS__'); } -const fragmentManifest = require("__V_DICTIONARY__"); +const fragmentManifest = require('__V_DICTIONARY__'); process.on('unhandledRejection', (reason, p) => { console.error('Unhandled Rejection at:', p, 'reason:', reason); @@ -115,10 +116,7 @@ if (process.env.NODE_ENV === 'production') { hiddie.use(locals); hiddie.use(helmet()); hiddie.use(cors); - hiddie.use( - '/', - serveStatic(voltranConfig.distFolder + '/public') - ); + hiddie.use('/', serveStatic(`${voltranConfig.distFolder}/public`)); hiddie.use(cookieParser()); hiddie.use(utils); hiddie.use(handleUrls); @@ -140,7 +138,7 @@ export default () => { compression(), locals, helmet(), - serveStatic(voltranConfig.distFolder + '/public'), + serveStatic(`${voltranConfig.distFolder}/public`), cookieParser(), utils, handleUrls, diff --git a/src/tools/run.js b/src/tools/run.js index c783bf2..4f17128 100644 --- a/src/tools/run.js +++ b/src/tools/run.js @@ -5,14 +5,18 @@ function run(fn, options) { const start = new Date(); console.log( - 'src/tools/run.js', 'run', `Starting '${task.name}${options ? ` (${options})` : ''}'...` + 'src/tools/run.js', + 'run', + `Starting '${task.name}${options ? ` (${options})` : ''}'...` ); return task(options).then(resolution => { const end = new Date(); const time = end.getTime() - start.getTime(); console.log( - 'src/tools/run.js', 'run', `Finished '${task.name}${options ? ` (${options})` : ''}' after ${time} ms` + 'src/tools/run.js', + 'run', + `Finished '${task.name}${options ? ` (${options})` : ''}' after ${time} ms` ); return resolution; }); diff --git a/src/tools/start.js b/src/tools/start.js index 5b2a284..a224765 100644 --- a/src/tools/start.js +++ b/src/tools/start.js @@ -36,10 +36,12 @@ async function start() { ); hiddie.use(webpackHotMiddleware(clientCompiler)); - hiddie.use(webpackHotServerMiddleware(compiler, { - chunkName: 'server', - serverRendererOptions: { hiddie } - })); + hiddie.use( + webpackHotServerMiddleware(compiler, { + chunkName: 'server', + serverRendererOptions: { hiddie } + }) + ); http.createServer(hiddie.run).listen(voltranConfig.port); diff --git a/src/universal/common/network/apiUtils.js b/src/universal/common/network/apiUtils.js index 08cc707..d83a266 100644 --- a/src/universal/common/network/apiUtils.js +++ b/src/universal/common/network/apiUtils.js @@ -1,5 +1,5 @@ import Request from '../../model/Request'; -import {createCacheManagerInstance} from '../../core/cache/cacheUtils'; +import { createCacheManagerInstance } from '../../core/cache/cacheUtils'; function createApiClient(apiManager) { const cacheManager = createCacheManagerInstance(); @@ -23,9 +23,9 @@ function createApiClient(apiManager) { function getPayload(url, method, params, configArgument) { let payload; if (configArgument) { - payload = {url, method, params, ...configArgument}; + payload = { url, method, params, ...configArgument }; } else { - payload = {url, method, params}; + payload = { url, method, params }; } return payload; } @@ -48,7 +48,7 @@ function createApiClient(apiManager) { if (cacheResponse && !cacheResponse.isExpired) { // console.log('Came from cache', cacheSettings.cacheKey); request = getRequest(method, url, paramsArgument, configArgument, { - cacheResponse: cacheResponse.cacheValue, + cacheResponse: cacheResponse.cacheValue }); } else { // console.log('Not exist cache, request sent', cacheSettings.cacheKey); @@ -97,9 +97,9 @@ function createApiClient(apiManager) { options(url, config, cacheSettings) { return makeRequest('options', url, config, null, cacheSettings); - }, + } }; } // eslint-disable-next-line import/prefer-default-export -export {createApiClient}; +export { createApiClient }; diff --git a/src/universal/components/Html.js b/src/universal/components/Html.js index d20fc00..61cf88e 100644 --- a/src/universal/components/Html.js +++ b/src/universal/components/Html.js @@ -22,7 +22,15 @@ function componentClassName(componentName, context) { return context.query && context.query.id ? `${componentName}_${context.query.id}` : componentName; } -function Html({ componentName, children, styleTags, initialState, fullWidth, isMobileFragment, context }) { +function Html({ + componentName, + children, + styleTags, + initialState, + fullWidth, + isMobileFragment, + context +}) { return `
${styleTags} @@ -30,7 +38,9 @@ function Html({ componentName, children, styleTags, initialState, fullWidth, isM
+ class="${voltranConfig.prefix}-voltran-body voltran-body ${ + isMobileFragment ? 'mobile' : '' + }${fullWidth ? 'full' : ''} ${componentClassName(componentName, context)}"> ${children}
REPLACE_WITH_LINKS
diff --git a/src/universal/components/Preview.js b/src/universal/components/Preview.js index 0d08236..87e7f17 100644 --- a/src/universal/components/Preview.js +++ b/src/universal/components/Preview.js @@ -1,6 +1,6 @@ const appConfig = require('__APP_CONFIG__'); -export default (body, componentNames = [], title = null) => { +export default (body, title = null) => { const additionalTitle = title ? ` - ${title}` : ''; function cr(condition, ok, cancel) { @@ -14,7 +14,8 @@ export default (body, componentNames = [], title = null) => { - ${cr(appConfig.showPreviewFrame, + ${cr( + appConfig.showPreviewFrame, `