Skip to content
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

Content-Type is changed to text/html and script tag is inserted #39

Open
hankei6km opened this issue May 23, 2023 · 6 comments
Open

Content-Type is changed to text/html and script tag is inserted #39

hankei6km opened this issue May 23, 2023 · 6 comments

Comments

@hankei6km
Copy link

I am sending JSON using res.json in Express. In this case Content-Type of res headers should be application/json.
But in Nodebox Runtime it is changed to text/html.

dev-tools-hello-header

And <script> tag is inserted.
dev-tools-hello

step to reproduce

A sandbox for step to reproduce.
https://codesandbox.io/p/sandbox/reproduce-btoken-json-responce-fohukt

Server part code:
https://codesandbox.io/p/sandbox/reproduce-content-type-is-changed-to-text-html-fohukt?file=%2Fbox-src%2Fvite-project%2Fserver.js%3A1%2C1

Express + Vite server is started inside the Nodebox environment and fetch the JSON from the preview window.
This will result in a parse error.

nodebox

Start the above server without using Nodebox with npm run server.
This is displayed as expected.
nodejs

@DeMoorJasper
Copy link
Collaborator

It shouldn't change this if encoding is set to anything non-html will check this asap and post any updates here

@DeMoorJasper
Copy link
Collaborator

Screenshot 2023-05-26 at 09 10 36

Just checked and this likely indicates that your returned response from the http server is html, unfortunately in this case we can't really fix this

@hankei6km
Copy link
Author

@DeMoorJasper

Thanks for the check.

I will consider not using Express res.json in the Nodebox environment.

@brianjenkins94
Copy link

brianjenkins94 commented Jun 10, 2023

Wait, why can't this be fixed? I've run into this too.

@hankei6km is using res.json() which sends application/json. Nodebox is changing it to text/html somehow.

@DeMoorJasper
Copy link
Collaborator

Wait, why can't this be fixed? I've run into this too.

@hankei6km is using res.json() which sends application/json. Nodebox is changing it to text/html somehow.

I didn't look too deeply into this but seeing that it is using res.json it's probably something going wrong in nodebox, reopening this ticket

@DeMoorJasper DeMoorJasper reopened this Jun 10, 2023
@hankei6km
Copy link
Author

@DeMoorJasper

I've already stopped using Express on Nodebox and am using another method. So I can't contribute much.

However, Additional information that may be helpful if you look deeper

This is a forked sandbox from example.

https://codesandbox.io/p/sandbox/reproduce-content-type-markdown-nodebox-drv44h

I added only one line to index.js. Expected response is text/markdown; charset=utf-8

  res.setHeader('content-type', 'text/makdown');

But in Nodebox it is text/html.

nodebox-not-markdown

Of course, when I run it with native Node.js, it is text/markdown
https://codesandbox.io/p/sandbox/reproduce-content-type-markdown-native-nodejs-w48cz2
nodejs-markdown

Therefore, similar problems may occur outside of res.json function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants