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

newlines "\n" and whitespaces are not preserved when the API call is made via extensions. #285

Open
saicharan0112 opened this issue Dec 21, 2024 · 3 comments
Labels
work completed Work for this has been completed but it may not yet be merged / released
Milestone

Comments

@saicharan0112
Copy link

I have a js file that returns a certain text with proper formatting and i am running this on a nodejs server. When I use curl to get the response of the API, the formatting of the response is preserved however when I use the extensions feature inside glance, I don't see that anymore. I am new to the world of servers and APIs so I am not sure what exactly I am missing here. Below is the extensions usage snippet from the glance.yml file. Any help is appreciate.

        widgets:
        - type: extension
          url: http://192.168.0.109:3000/getAlerts
          parameters:
            state: TX
@saicharan0112 saicharan0112 changed the title newlines "\n" are not preserved when the API call is made via extensions. newlines "\n" and whitespaces are not preserved when the API call is made via extensions. Dec 21, 2024
@svilenmarkov
Copy link
Member

Hey, thanks for reporting this. This is a bug I'll fix for the next release but for the time being you can still return HTML in your extension's content that can contain any formatting you like.

@svilenmarkov svilenmarkov added this to the v0.7.0 milestone Dec 22, 2024
@svilenmarkov svilenmarkov added the work completed Work for this has been completed but it may not yet be merged / released label Dec 22, 2024
@saicharan0112
Copy link
Author

Hey, sorry for my late reply and thanks for your reply (and fix! based on the label you added). I did try returning the entire html but all the p tags are retained. I checked earlier issues on this repo and saw the suggestion to use ngnix with some config addition. I am not familiar with ngnix (just enough node js to build serve the js code as an API). If you can suggest any methods, I am happy to try.

@svilenmarkov
Copy link
Member

In order to be able to serve HTML you need to add two things:

Change your config to also include allow-potentially-dangerous-html:

- type: extension
  url: http://192.168.0.109:3000/getAlerts
  allow-potentially-dangerous-html: true
  parameters:
  state: TX

Assuming you're using Express in your JS file, add the Widget-Content-Type header:

res.set('Widget-Content-Type', 'html')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work completed Work for this has been completed but it may not yet be merged / released
Projects
None yet
Development

No branches or pull requests

2 participants