Skip to content

fix: support HTTP URLs in getTitle() for title fetching#21

Open
malladinagarjuna2 wants to merge 1 commit intoneutralinojs:masterfrom
malladinagarjuna2:fix/http-urls-in-getTitle
Open

fix: support HTTP URLs in getTitle() for title fetching#21
malladinagarjuna2 wants to merge 1 commit intoneutralinojs:masterfrom
malladinagarjuna2:fix/http-urls-in-getTitle

Conversation

@malladinagarjuna2
Copy link
Copy Markdown

Fixes #20

Problem

getTitle() only used https.get(), so neu appify http://localhost:3333 (and any HTTP URL) failed with:

Users had to pass --title for HTTP URLs.

Solution

  • Parse the URL with the built-in URL constructor and choose the request module by protocol.
  • Use http for http: and https for https: when fetching the page to extract the <title>.
  • Reject with clear errors for invalid URLs and unsupported protocols (e.g. file:).
  • Use reject(err) instead of reject('') in getTitle() so callers get a proper error.

Changes

  • index.js: Added http and url modules; in getTitle(), select http or https from new URL(url).protocol and call protocol.get(url, ...). Exported getTitle for tests.
  • package.json: Added test:getTitle script.

Testing

  • npm run test:getTitle (HTTP + invalid protocol; HTTPS optional if network available).
  • Manually: npx serve sample-website -p 3333 then neu appify http://localhost:3333 — app is created with the page title.

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

Successfully merging this pull request may close these issues.

getTitle() only uses HTTPS; HTTP URLs break title fetching

1 participant