tus-node-server
tus-node-server copied to clipboard
Events & Errors should be implemented in the handler instead of DataStore's
Currently, events like the EVENT_FILE_CREATED
are emitted from the DataStore level (like so), and Error's that include response information are thrown from the DataStore level as well (like so).
Since neither of these are the concern of the DataStore, and rather the HTTP request handler, they should be abstracted one level above to the handler. The DataStore should be purely focused on reading & writing.
This will also make #61 possible.
I've seen your last commit https://github.com/tus/tus-node-server/commit/faf40f0cc87bffc3b4ffe1632d2aadcee9537f26 and I'm wondering why we can't access to the req
and resp
when event like EVENT_FILE_CREATED
are fired.
My use case explaining my suggestion:
I'm using the server with Express. I have an authentication with a JWT token where I have a user_id.
For this purpose, I have a header authorization
with a value bearer my_jwt_token
.
In this context, I need access to req.headers
to be able to say to the system, for this created file, assign the original name, an id and a size with the authenticated user deduced from the token.
I need to set a return content. So, I also need access to the response.
I don't say change had to be made as my use case may not fit most people usages. It can at least help you understanding why I think exposing request and response in events should be done IMO.