Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

[DRAFT] refactor: migrated header middleware setters to fastify #807

Closed
wants to merge 26 commits into from

Conversation

giulianok
Copy link
Member

Description

Motivation and Context

How Has This Been Tested?

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)
  • Dependency update
  • Security update

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • These changes should be applied to a maintenance branch.
  • This change requires cross browser checks.
  • Performance tests should be ran against the server prior to merging.
  • This change impacts caching for client browsers.
  • This change impacts HTTP headers.
  • This change adds additional environment variable requirements for One App users.
  • I have added the Apache 2.0 license header to any new files created.

What is the Impact to Developers Using One App?

@github-actions
Copy link
Contributor

github-actions bot commented Aug 17, 2022

Size Change: +7.59 kB (+1%)

Total Size: 688 kB

Filename Size Change
./build/app/app.js 173 kB +7.5 kB (+5%) 🔍
./build/app/app~vendors.js 387 kB +76 B (0%)
./build/app/service-worker-client.js 7.26 kB -3 B (0%)
./build/app/vendors.js 114 kB +16 B (0%)
ℹ️ View Unchanged
Filename Size
./build/app/runtime.js 7.07 kB

compressed-size-action

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2022

This pull request is stale because it has been open 30 days with no activity.

@giulianok giulianok marked this pull request as ready for review November 4, 2022 16:24
@giulianok giulianok requested a review from a team as a code owner November 4, 2022 16:24
@giulianok giulianok requested a review from a team as a code owner November 4, 2022 16:24
@@ -37,7 +37,8 @@ export default async function initClient() {

await loadPrerenderScripts(store.getState());

const { redirectLocation, renderProps } = await matchPromise({ history, routes });
const asd = await matchPromise({ history, routes });
const { redirectLocation, renderProps } = asd;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be collapsed back into a one liner? or a more detailed variable name chose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, this is from testing, will remove asd

}

// TODO: expose the id to the client?
// res.header('Correlation-Id', req.headers['correlation-id']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we clear this TODO before merge, or is this a later TODO?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this got carried over and it has been in the project for ~3 years https://github.com/americanexpress/one-app/blob/main/src/server/middleware/ensureCorrelationId.js#L25-L26, I'll remove it, I don't think we need it

if (!renderProps) {
res.sendStatus(404);
// TODO: test this behaivor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have we done this now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's covered, will remove

extraThunkArguments: { fetchClient },
});

// TODO: namespace?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we clear this TODO before merge?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has been here for ~3 years https://github.com/americanexpress/one-app/blob/main/src/server/middleware/createRequestStore.js#L61, i guess we do not need it, i'll remove it

request.clientModuleMapCache = getClientModuleMapCache();
} catch (err) {
console.error('error creating store for request', err);
// TODO: migrate `renderStaticErrorPage`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we clear this TODO before merge?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, can be removed, the next line calls the fn which has been migrated

'acceptsLanguages',
'baseUrl',
'forwarded',
// 'forwarded', // not in use (?) need to find a fastify equivalent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is a TODO can we mark it as such? and then, can we clear this TODO before merge?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, this can be enabled again since forwardedHeaderParser was migrated already and injects the forwarded key into the request object

cb();
} catch (error) {
console.error('--ERROR', error);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing was meaningfully changed here right? just light refactoring?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

light refactoring. The problem with react router 3 is that, if the fn throws an error, the request hangs and nothing happens. I'll revert it since this will require an extra effort to fix all the other samples and, at the end, it's just a sample

@giulianok giulianok changed the title refactor: migrated header middleware setters to fastify [DRAFT] refactor: migrated header middleware setters to fastify Nov 7, 2022
@giulianok giulianok mentioned this pull request Nov 8, 2022
14 tasks
@@ -26,6 +26,7 @@ const styles = css`
`;

export function FashionablyLateFrank() {
// eslint-disable-next-line react/no-unknown-property
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add explanations for all disabled rules

Comment on lines +33 to +34
const matchedDomain = frameAncestorDomains.find((domain) => matcher.isMatch(trimmedReferrer, `${domain}/*`)
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for a lint issue?

createRequestStoreHook(request, reply, oneApp);

if (getServerPWAConfig().serviceWorker && request.url === '/_/pwa/shell') {
await appShell(request);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weren't we previously caching this until module map update?

filteredRequest.originalUrl = request.raw.url;

// Not available in Fastify
filteredRequest.baseUrl = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a breaking change? Seems so

});

// expect(response.status).toBe(204);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// expect(response.status).toBe(204);
expect(response.status).toBe(204);

}),
status: 200,

test('calls the expected hooks to render pwa html shell', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test('calls the expected hooks to render pwa html shell', async () => {
it('calls the expected hooks to render pwa html shell', async () => {

use it throughout

import addFrameOptionsHeader from '../../src/server/plugins/addFrameOptionsHeader';
import addCacheHeaders from '../../src/server/plugins/addCacheHeaders';
import {
// eslint-disable-next-line import/named
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add explanation

beforeEach(() => {
jest.resetModules();
// jest.resetModules();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// jest.resetModules();

/*
NOTE: This temporarily fix is needed until
this PR is reviewed, merged, and published
https://github.com/fastify/fastify-cors/pull/234
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is merged now

@@ -43,7 +43,7 @@
"drop-module": "drop-module",
"set-middleware": "set-middleware",
"set-dev-endpoints": "node scripts/set-dev-endpoints.js",
"postinstall": "npm run build",
"postinstall": "node scripts/temp-fix-fastify-cors.js && npm run build",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"postinstall": "node scripts/temp-fix-fastify-cors.js && npm run build",
"postinstall": "npm run build",

@giulianok
Copy link
Member Author

moved to #878

@giulianok giulianok closed this Dec 6, 2022
@JAdshead JAdshead deleted the refactor/create-store-fastify-migration branch September 15, 2023 20:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants