Why is my image not rendering in a simple HTML page served with D?
Damjan
smartdeveloper514 at gmail.com
Sun May 18 21:40:17 UTC 2025
Hi
I'm experimenting with using D to serve a basic HTML page (using
vibe.d), and while the HTML loads fine, none of my image files
are rendering in the browser — I only see broken icons.
Here’s the relevant part of my D code that serves the HTML:
import vibe.vibe;
void handleRequest(HTTPServerRequest req, HTTPServerResponse res)
{
res.writeBody(`<!DOCTYPE html>
<html>
<head><title>Image Test</title></head>
<body>
<h1>Hello from D</h1>
<img src="images/logo.png" alt="Logo">
</body>
</html>`, "text/html");
}
void main()
{
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, &handleRequest);
runApplication();
}
And my folder structure looks like this:
project/
├── source/
│ └── app.d
├── public/
│ └── images/
│ └── logo.png
├── dub.json
What I tried:
Verified the image exists at public/images/logo.png
Tried both images/logo.png and /images/logo.png in the HTML
Ensured file permissions are readable
The server runs and returns the HTML just fine
Opened the image directly in the browser via
http://localhost:8080/images/logo.png → 404
Questions:
Do I need to explicitly configure vibe.d to serve static files
from the public folder?
Is there a helper for serving static assets (like
serveStaticFiles) that I’m missing?
Is this a routing issue or a path resolution problem?
I’m still pretty new to using D for web servers, so any help
would be appreciated!
More information about the Digitalmars-d-learn
mailing list