-
Notifications
You must be signed in to change notification settings - Fork 87
[DRAFT] refactor: migrated header middleware setters to fastify #807
Conversation
Size Change: +7.59 kB (+1%) Total Size: 688 kB
ℹ️ View Unchanged
|
…hub.com/americanexpress/one-app into refactor/create-store-fastify-migration
This pull request is stale because it has been open 30 days with no activity. |
src/client/initClient.jsx
Outdated
@@ -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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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']); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
src/server/utils/safeRequest.js
Outdated
'acceptsLanguages', | ||
'baseUrl', | ||
'forwarded', | ||
// 'forwarded', // not in use (?) need to find a fastify equivalent |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
@@ -26,6 +26,7 @@ const styles = css` | |||
`; | |||
|
|||
export function FashionablyLateFrank() { | |||
// eslint-disable-next-line react/no-unknown-property |
There was a problem hiding this comment.
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
const matchedDomain = frameAncestorDomains.find((domain) => matcher.isMatch(trimmedReferrer, `${domain}/*`) | ||
); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 = ''; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// expect(response.status).toBe(204); | |
expect(response.status).toBe(204); |
}), | ||
status: 200, | ||
|
||
test('calls the expected hooks to render pwa html shell', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// jest.resetModules(); |
/* | ||
NOTE: This temporarily fix is needed until | ||
this PR is reviewed, merged, and published | ||
https://github.com/fastify/fastify-cors/pull/234 |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"postinstall": "node scripts/temp-fix-fastify-cors.js && npm run build", | |
"postinstall": "npm run build", |
moved to #878 |
Description
Motivation and Context
How Has This Been Tested?
Types of Changes
Checklist:
What is the Impact to Developers Using One App?