Skip to content

Proxy http-server in Webpack dev mode - #100

Merged
hvianna merged 1 commit into
hvianna:devfrom
Borewit:proxy-server-in-dev-mode
Jul 19, 2025
Merged

Proxy http-server in Webpack dev mode#100
hvianna merged 1 commit into
hvianna:devfrom
Borewit:proxy-server-in-dev-mode

Conversation

@Borewit

@Borewit Borewit commented Jul 19, 2025

Copy link
Copy Markdown
Contributor

This extends the Webpack development mode to be able to access the HTTP server backend.

Follow up of:

This requires to start both:

  1. the http-server npm start, accessible via http://localhost:8080/
  2. the development server 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:2px
Loading

Future 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.

@Borewit Borewit changed the title Proxy http-server in dev mode Proxy http-server in Webpack dev mode Jul 19, 2025
@Borewit
Borewit marked this pull request as draft July 19, 2025 08:55
@Borewit
Borewit force-pushed the proxy-server-in-dev-mode branch from 90e670a to 2368ac0 Compare July 19, 2025 09:11
@Borewit
Borewit marked this pull request as ready for review July 19, 2025 09:11
@Borewit
Borewit force-pushed the proxy-server-in-dev-mode branch from 2368ac0 to add1ca9 Compare July 19, 2025 10:46
@Borewit
Borewit force-pushed the proxy-server-in-dev-mode branch from add1ca9 to bbd9f38 Compare July 19, 2025 13:13
@hvianna
hvianna merged commit 8c0b9a8 into hvianna:dev Jul 19, 2025
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.

2 participants