Skip to content

Commit f4c3829

Browse files
authored
Merge pull request #5297 from HSLdevcom/DT-6770
DT-6770 remove local storage emitter code
2 parents ef3014d + accd558 commit f4c3829

File tree

10 files changed

+67
-195
lines changed

10 files changed

+67
-195
lines changed

app/component/AppBarHsl.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import { clearOldSearches, clearFutureRoutes } from '../util/storeUtils';
99
import { getJson } from '../util/xhrPromise';
1010

1111
const SiteHeader = lazy(() => import('@hsl-fi/site-header'));
12-
const SharedLocalStorageObserver = lazy(
13-
() => import('@hsl-fi/shared-local-storage'),
14-
);
1512

1613
const clearStorages = context => {
1714
clearOldSearches(context);
@@ -143,12 +140,6 @@ const AppBarHsl = ({ lang, user, favourites }, context) => {
143140
notificationApiUrls={notificationApiUrls}
144141
/>
145142
)}
146-
{config.localStorageEmitter && (
147-
<SharedLocalStorageObserver
148-
keys={['saved-searches', 'favouriteStore']}
149-
url={config.localStorageEmitter}
150-
/>
151-
)}
152143
</Suspense>
153144
</>
154145
);

app/configurations/config.hsl.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ const SUGGESTION_URL = process.env.CONTENT_DOMAIN
2020
? `${process.env.CONTENT_DOMAIN}/api/v1/search/suggestions`
2121
: 'https://content.hsl.fi/api/v1/search/suggestions'; // old url
2222

23-
const localStorageEmitter =
24-
process.env.USE_EMITTER && rootLink + '/local-storage-emitter';
25-
2623
const IS_DEV =
2724
process.env.RUN_ENV === 'development' ||
2825
process.env.NODE_ENV !== 'production';
@@ -453,8 +450,6 @@ export default {
453450
sv: 'att-resa/Trafiken-just-nu',
454451
},
455452

456-
localStorageEmitter,
457-
458453
vehicleRental: {
459454
minZoomStopsNearYou: 10,
460455
showFullInfo: true,

app/server.js

Lines changed: 67 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import { getConfiguration } from './config';
4242
import { getAnalyticsInitCode } from './util/analyticsUtils';
4343

4444
import { historyMiddlewares, render } from './routes';
45-
import { LOCAL_STORAGE_EMITTER_PATH } from './util/path';
4645
import ErrorHandlerSSR from './component/ErrorHandlerSSR';
4746

4847
// Look up paths for various asset files
@@ -327,94 +326,85 @@ export default async function serve(req, res, next) {
327326
res.write(`<html lang="${locale}">\n`);
328327
res.write('<head>\n');
329328

330-
// local storage emitter is used from a hidden iframe and these are not necessary for it
331-
if (req.url !== LOCAL_STORAGE_EMITTER_PATH) {
332-
// Write preload hints before doing anything else
333-
if (process.env.NODE_ENV !== 'development') {
334-
res.write(getAnalyticsInitCode(config, req.hostname));
335-
336-
const preloads = [
337-
{ as: 'style', href: config.URL.FONT },
338-
{
339-
as: 'style',
340-
href: `${ASSET_URL}/${assets[`${config.CONFIG}_theme.css`]}`,
341-
crossorigin: true,
342-
},
343-
...mainAssets.map(asset => ({
344-
as: asset.endsWith('.css') ? 'style' : 'script',
345-
href: `${ASSET_URL}/${asset}`,
346-
crossorigin: true,
347-
})),
348-
];
349-
350-
preloads.forEach(({ as, href, crossorigin }) =>
351-
res.write(
352-
`<link rel="preload" as="${as}" ${
353-
crossorigin ? 'crossorigin' : ''
354-
} href="${href}">\n`,
355-
),
356-
);
357-
358-
const preconnects = [config.URL.API_URL, config.URL.MAP_URL];
359-
360-
if (config.staticMessagesUrl) {
361-
preconnects.push(config.staticMessagesUrl);
362-
}
329+
// Write preload hints before doing anything else
330+
if (process.env.NODE_ENV !== 'development') {
331+
res.write(getAnalyticsInitCode(config, req.hostname));
332+
333+
const preloads = [
334+
{ as: 'style', href: config.URL.FONT },
335+
{
336+
as: 'style',
337+
href: `${ASSET_URL}/${assets[`${config.CONFIG}_theme.css`]}`,
338+
crossorigin: true,
339+
},
340+
...mainAssets.map(asset => ({
341+
as: asset.endsWith('.css') ? 'style' : 'script',
342+
href: `${ASSET_URL}/${asset}`,
343+
crossorigin: true,
344+
})),
345+
];
346+
347+
preloads.forEach(({ as, href, crossorigin }) =>
348+
res.write(
349+
`<link rel="preload" as="${as}" ${
350+
crossorigin ? 'crossorigin' : ''
351+
} href="${href}">\n`,
352+
),
353+
);
363354

364-
preconnects.forEach(href =>
365-
res.write(`<link rel="preconnect" crossorigin href="${href}">\n`),
366-
);
355+
const preconnects = [config.URL.API_URL, config.URL.MAP_URL];
367356

368-
res.write(
369-
`<link rel="stylesheet" type="text/css" crossorigin href="${ASSET_URL}/${
370-
assets[`${config.CONFIG}_theme.css`]
371-
}"/>\n`,
372-
);
373-
mainAssets
374-
.filter(asset => asset.endsWith('.css'))
375-
.forEach(asset =>
376-
res.write(
377-
`<link rel="stylesheet" type="text/css" crossorigin href="${ASSET_URL}/${asset}"/>\n`,
378-
),
379-
);
357+
if (config.staticMessagesUrl) {
358+
preconnects.push(config.staticMessagesUrl);
380359
}
381360

361+
preconnects.forEach(href =>
362+
res.write(`<link rel="preconnect" crossorigin href="${href}">\n`),
363+
);
364+
382365
res.write(
383-
`<link rel="stylesheet" type="text/css" href="${config.URL.FONT}"/>\n`,
366+
`<link rel="stylesheet" type="text/css" crossorigin href="${ASSET_URL}/${
367+
assets[`${config.CONFIG}_theme.css`]
368+
}"/>\n`,
384369
);
370+
mainAssets
371+
.filter(asset => asset.endsWith('.css'))
372+
.forEach(asset =>
373+
res.write(
374+
`<link rel="stylesheet" type="text/css" crossorigin href="${ASSET_URL}/${asset}"/>\n`,
375+
),
376+
);
377+
}
378+
res.write(
379+
`<link rel="stylesheet" type="text/css" href="${config.URL.FONT}"/>\n`,
380+
);
385381

386-
res.write(`<script>\n${polyfills}\n</script>\n`);
382+
res.write(`<script>\n${polyfills}\n</script>\n`);
387383

388-
const head = Helmet.rewind();
384+
const head = Helmet.rewind();
389385

390-
if (head) {
391-
res.write(head.title.toString());
392-
res.write(head.meta.toString());
393-
res.write(head.link.toString());
394-
}
386+
if (head) {
387+
res.write(head.title.toString());
388+
res.write(head.meta.toString());
389+
res.write(head.link.toString());
395390
}
396391

397392
res.write('</head>\n');
398393
res.write('<body>\n');
399394

400-
// local storage emitter is used from a hidden iframe and these are not necessary for it
401-
if (req.url !== LOCAL_STORAGE_EMITTER_PATH) {
402-
if (process.env.NODE_ENV !== 'development') {
403-
res.write('<script>\n');
404-
res.write(`fetch('${ASSET_URL}/${assets[spriteName]}')
395+
if (process.env.NODE_ENV !== 'development') {
396+
res.write('<script>\n');
397+
res.write(`fetch('${ASSET_URL}/${assets[spriteName]}')
405398
.then(function(response) {return response.text();}).then(function(blob) {
406399
var div = document.createElement('div');
407400
div.innerHTML = blob;
408401
document.body.insertBefore(div, document.body.childNodes[0]);
409402
});`);
410-
res.write('</script>\n');
411-
} else {
412-
res.write('<div>\n');
413-
res.write(
414-
fs.readFileSync(`${appRoot}_static/${spriteName}`).toString(),
415-
);
416-
res.write('</div>\n');
417-
}
403+
res.write('</script>\n');
404+
} else {
405+
res.write('<div>\n');
406+
res.write(fs.readFileSync(`${appRoot}_static/${spriteName}`).toString());
407+
res.write('</div>\n');
418408
}
419409

420410
res.write(contentWithBreakpoint || '<div id="app" />');
@@ -425,16 +415,13 @@ export default async function serve(req, res, next) {
425415
)};\n</script>\n`,
426416
);
427417

428-
// local storage emitter is used from a hidden iframe and it does not use relay
429-
if (req.url !== LOCAL_STORAGE_EMITTER_PATH) {
430-
res.write('<script>\n');
431-
res.write(
432-
`window.__RELAY_PAYLOADS__ = ${serialize(JSON.stringify(relayData), {
433-
isJSON: true,
434-
})}`,
435-
);
436-
res.write('\n</script>\n');
437-
}
418+
res.write('<script>\n');
419+
res.write(
420+
`window.__RELAY_PAYLOADS__ = ${serialize(JSON.stringify(relayData), {
421+
isJSON: true,
422+
})}`,
423+
);
424+
res.write('\n</script>\n');
438425

439426
if (process.env.NODE_ENV === 'development') {
440427
res.write('<script async src="/proxy/js/main.js"></script>\n');

app/util/path.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const PREFIX_ITINERARY_SUMMARY = 'reitti';
1717
export const PREFIX_DISRUPTION = 'hairiot';
1818
export const PREFIX_TIMETABLE = 'aikataulu';
1919
export const stopUrl = id => id;
20-
export const LOCAL_STORAGE_EMITTER_PATH = '/local-storage-emitter';
2120
export const EMBEDDED_SEARCH_PATH = '/haku';
2221
export const PREFIX_RENTALVEHICLES = 'skuutit';
2322

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@
138138
"@hsl-fi/hooks": "1.2.4",
139139
"@hsl-fi/modal": " ^0.3.2",
140140
"@hsl-fi/sass": " ^0.2.0",
141-
"@hsl-fi/shared-local-storage": "0.4.0",
142141
"@hsl-fi/shimmer": "0.1.2",
143142
"@hsl-fi/site-header": "4.5.0",
144143
"@mapbox/sphericalmercator": "1.1.0",

server/server.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@ function setUpStaticFolders() {
113113
},
114114
}),
115115
);
116-
117-
if (config.localStorageEmitter) {
118-
app.use(
119-
'/local-storage-emitter',
120-
express.static(path.join(staticFolder, 'emitter')),
121-
);
122-
}
123116
}
124117

125118
function setUpMiddleware() {

0 commit comments

Comments
 (0)