stackblitz / webcontainer-core

Dev environments. In your web app.
https://webcontainers.io
MIT License
3.78k stars 145 forks source link

return pure json, if postman or any backend service fetch the api with content Ttype application/json #122

Closed yimity closed 2 years ago

yimity commented 3 years ago

Is your feature request related to a problem? Please describe. if i editting a nestjs or nodejs backend service in stackblitz, and a url will return a json format data. if i visit the url or fetch it in console in the same browser, it will show correct, but if i visit this url in other service, like other backend or postman, it will return a html document with many javascript code. so it will broken the app.

Describe the solution you'd like if fetch this url with a content type application/json in header or other param, it should return a pure json data or pure data returned by app with no addition data by stackblitz.

Describe alternatives you've considered //

Additional context Editor Url: https://stackblitz.com/edit/nestjs-starter-mw5tvn?. App Url : https://nestjs-starter-mw5tvn.stackblitz.io

if i visit the App Url. in same browser, it shows {"hi":"Hello World!"}, or fetch it in same browser console it also shows {"hi":"Hello World!"}. code: fetch('https://nestjs-starter-mw5tvn--3000.local.webcontainer.io/').then(response => { return response.json(); }).then((data) => { console.log(data); }) but fetch App Url from other service such as postman, it shows a html with some javascript code.

d3lm commented 3 years ago

Do you have a reproduction? Please provide as much information as possible and we'll do our best to fix it. A link to a project and clear steps to reproduce this would be the minimum. Thanks a lot for providing your feedback!

SamVerschueren commented 3 years ago

So you are setting up a server on StackBlitz and try to send requests with postman to the endpoint? That will unfortunately never work, Chrome does not allow us to expose the server to the outside. So as long as you are sending it inside Chrome, that should work. But it will not work with postman or curl or whatever.

yimity commented 3 years ago

So you are setting up a server on StackBlitz and try to send requests with postman to the endpoint? That will unfortunately never work, Chrome does not allow us to expose the server to the outside. So as long as you are sending it inside Chrome, that should work. But it will not work with postman or curl or whatever.

Yes, you are all right. but i visit this App Url from postman or other service outside the chrome, it shows contents, it works. so i think if the request header with a contentType applicatio/json, the output will be a pure json without the html and javascript code.

jrvidal commented 2 years ago

@yimity Seems like the original blitz links don't work anymore, so we can't really debug your issue, but if we understood correctly, you're attempting to access a server running in Stackblitz from an external tool. This is simply not possible and it's not something we can fix with current browser APIs.

Thanks for the report and please feel free to file more issues if you something broken.