[GH-ISSUE #8] Admin UI export json header error #4

Closed
opened 2026-05-23 08:38:03 -06:00 by gitea-mirror · 5 comments
Owner

Originally created by @theoparis on GitHub (Jul 7, 2021).
Original GitHub issue: https://github.com/appy-one/acebase-server/issues/8

Hi there. Thanks for making acebase, its amazing. I just ran into an issue when I click on the You can export the value of this node to json button in the admin ui.

acebase_1  | Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
acebase_1  |     at new NodeError (node:internal/errors:363:5)
acebase_1  |     at ServerResponse.setHeader (node:_http_outgoing:574:11)
acebase_1  |     at ServerResponse.header (/app/node_modules/express/lib/response.js:771:10)
acebase_1  |     at ServerResponse.json (/app/node_modules/express/lib/response.js:264:10)
acebase_1  |     at ServerResponse.send (/app/node_modules/express/lib/response.js:158:21)
acebase_1  |     at /app/node_modules/acebase-server/src/acebase-server.js:2162:25 {
acebase_1  |   code: 'ERR_HTTP_HEADERS_SENT'

This occurs in the acebase server file on line 2162. Everything else such as logging in and navigating seems to work fine.

Also, not sure if this is a super useful idea, but it would be nice to see acebase server be able to be used as a middleware, so you can use it in an existing express app instead of creating a new one and listening on a different port.

Originally created by @theoparis on GitHub (Jul 7, 2021). Original GitHub issue: https://github.com/appy-one/acebase-server/issues/8 Hi there. Thanks for making acebase, its amazing. I just ran into an issue when I click on the `You can export the value of this node to json` button in the admin ui. ``` acebase_1 | Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client acebase_1 | at new NodeError (node:internal/errors:363:5) acebase_1 | at ServerResponse.setHeader (node:_http_outgoing:574:11) acebase_1 | at ServerResponse.header (/app/node_modules/express/lib/response.js:771:10) acebase_1 | at ServerResponse.json (/app/node_modules/express/lib/response.js:264:10) acebase_1 | at ServerResponse.send (/app/node_modules/express/lib/response.js:158:21) acebase_1 | at /app/node_modules/acebase-server/src/acebase-server.js:2162:25 { acebase_1 | code: 'ERR_HTTP_HEADERS_SENT' ``` This occurs in the acebase server file on line 2162. Everything else such as logging in and navigating seems to work fine. Also, not sure if this is a super useful idea, but it would be nice to see acebase server be able to be used as a middleware, so you can use it in an existing express app instead of creating a new one and listening on a different port.
Author
Owner

@theoparis commented on GitHub (Jul 7, 2021):

Seems like the solution is to use

               let data = ""
                const stream = {
                    write(chunk) {
                        data += chunk.toString()
                    }
                };

Instead of using res.write();

and then in .export().then simply use res.send(data)

I'm making a fork with updated dependencies and latest nodejs in the dockerfile. It also fixes this issue. I can make a PR as well

<!-- gh-comment-id:875281216 --> @theoparis commented on GitHub (Jul 7, 2021): Seems like the solution is to use ```js let data = "" const stream = { write(chunk) { data += chunk.toString() } }; ``` Instead of using res.write(); and then in .export().then simply use `res.send(data)` I'm making a fork with updated dependencies and latest nodejs in the dockerfile. It also fixes this issue. I can make a PR as well
Author
Owner

@appy-one commented on GitHub (Jul 7, 2021):

Thanks, I'll take a look at it. Your proposed fix does not stream the output though, which is problematic when exporting large nodes!

<!-- gh-comment-id:875531916 --> @appy-one commented on GitHub (Jul 7, 2021): Thanks, I'll take a look at it. Your proposed fix does not stream the output though, which is problematic when exporting large nodes!
Author
Owner

@appy-one commented on GitHub (Jul 7, 2021):

I've found what might be causing this. If there is an error while streaming the output, it does res.statusCode = 500 in ref.export's catch handler - which is obviously not allowed because it has been streaming data already. The error triggering this issue is probably a timeout for getting all data of a large node (or entire db?). How large is the data you are trying to export?

<!-- gh-comment-id:875582127 --> @appy-one commented on GitHub (Jul 7, 2021): I've found what might be causing this. If there is an error while streaming the output, it does ```res.statusCode = 500``` in ```ref.export```'s catch handler - which is obviously not allowed because it has been streaming data already. The error triggering this issue is probably a timeout for getting all data of a large node (or entire db?). How large is the data you are trying to export?
Author
Owner

@appy-one commented on GitHub (Jul 7, 2021):

I've fixed it by changing the stream to:

const stream = {
    write(chunk) {
        res.write(chunk);
    }
};

Commit will follow later today

<!-- gh-comment-id:875641541 --> @appy-one commented on GitHub (Jul 7, 2021): I've fixed it by changing the stream to: ```js const stream = { write(chunk) { res.write(chunk); } }; ``` Commit will follow later today
Author
Owner

@appy-one commented on GitHub (Jul 8, 2021):

Committed and published in acebase-server v1.2.3

<!-- gh-comment-id:876534599 --> @appy-one commented on GitHub (Jul 8, 2021): Committed and published in `acebase-server` v1.2.3
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase-server#4
No description provided.