-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add storeLog
in Config
#21
Conversation
src/interfaces/logSinkInterface.ts
Outdated
import { Log } from "../types"; | ||
|
||
class ILogSink { | ||
store = async (log: Log): Promise<void> => { |
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.
Let rename this to sendLog
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 would be better to address this one's these changes are merged here
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.
addressed it in backend implementation here
src/core/server.ts
Outdated
return res.status(mockResponse.statusCode).set(mockResponse.headers).end(mockResponse.body); | ||
console.debug("[Debug] Final Mock Response", mockResponse); | ||
|
||
res.locals.metadata = mockResponse.metadata; |
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.
Lets namespace metadata -> rq_metadata for scoping Requestly variables
src/core/server.ts
Outdated
app: Express | ||
|
||
constructor (port: number = 3000, configFetcher: IConfigFetcher, pathPrefix: string = "") { | ||
constructor (port: number = 3000, configFetcher: IConfigFetcher, logSink: ILogSink, pathPrefix: string = "") { |
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.
logSink should be optional. If not given, should default to empty Sink
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.
The api of the constructor has been updated in the other PR
src/middlewares/har.ts
Outdated
response: buildHarResponse(res, { body: responseBody }), | ||
} | ||
|
||
storageService.storeLog({ mockId: res.locals.metadata.mockId, HarEntry, }) |
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.
Faced a crash here while running locally
/Users/sahilgupta/Documents/dev/requestly/requestly-mock-server/src/middlewares/har.ts:28
storageService.storeLog({ mockId: res.locals.metadata.mockId, HarEntry, })
^
TypeError: Cannot read properties of undefined (reading 'mockId')
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.
I faced the same error once. Probably because of the order in which we are applying the metadata in core/server.ts
(but still the error shouldn't occur).
It suprisingly went away when I restarted the server and tested with the backend
- convert IConfig from class to interface - save src and sink in storageService instead of complete IConfig
Refactor: Exposed MockServer config [BREAKING CHANGE]
src/core/server.ts
Outdated
mockConfig: MockServerConfig; | ||
config: IConfig; |
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.
These both can be merged into 1 as both are same.
mockServerConfig: MockServerConfig
Also IConfig is incorrect name as prefix I
is used for marking abstract classes
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 can be converted to this
constructor (config: MockServerConfig)
src/services/storageService.ts
Outdated
|
||
class StorageService { | ||
configFetcher ?: IConfigFetcher|null = null; | ||
src: ISource | null = null; |
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.
src -> source
- combine config and mockServerConfig into serverOptions of MockServerClass (handle types accordingly) - remove the I prefix from storage config
} | ||
|
||
/* To make the constructor options optional except for storageConfig */ | ||
type MockServerConstructorOptions = Pick<MockServerOptions, 'storageConfig'> & Partial<MockServerOptions>; |
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.
we can't, we need port and pathprefix as optional there
will be an optional config argument that expects a function which handles the following log object
requestly-mock-server/src/types/index.ts
Lines 25 to 28 in 9fb9682
builds on top of #4 (now stale). Aims at getting the feature released.