Proxy http-server in Webpack dev mode
#100
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This extends the Webpack development mode to be able to access the HTTP server backend.
Follow up of:
This requires to start both:
npm start, accessible via http://localhost:8080/npm dev, accessible via http://localhost:9000/graph TD %% Nodes User[/"User Browser<br>localhost:9000"/] WebpackDevServer["Webpack Dev Server<br>localhost:9000"] HttpServer["http-server<br>localhost:8080"] MusicFile[["song.mp3<br>in ./music folder"]] %% Relationships User -->|Requests /| WebpackDevServer User -->|Requests /music/song.mp3| WebpackDevServer WebpackDevServer -->|Proxies /music/*| HttpServer HttpServer -->|Reads| MusicFile %% Styling style User fill:#e3f2fd,stroke:#2196f3,stroke-width:2px style MusicFile fill:#fff3e0,stroke:#ff9800,stroke-width:2pxFuture Considerations
While http-server is excellent for quickly serving static files to a browser, it is not intended to function as a backend API for web applications. It responds with HTML directory listings and lacks support for structured responses like JSON, which are essential when building RESTful services or programmatic file access. If your application needs to interact with the server via JavaScript (e.g., fetch or AJAX) and expects machine-readable data (e.g., JSON), a more suitable approach is to use a lightweight Node.js server (e.g., with Express or Fastify) that can explicitly serve both static files and JSON-based endpoints.
Note
Follow up:
http-serverwithfastify#101