$ sudo wget http://netcologne.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list $ sudo apt-get update && sudo apt-get -y --allow-unauthenticated install --reinstall d-apt-keyring && sudo apt-get update
Thereafter
$ sudo apt-get install dub
$ cd /home/< >/projects $ dub init < >
This operation will create the following file structure in your project folder.
public/ source/ app.d views/ package.json
"dependencies": { "vibe-d": ">=0.7.16" }
Now, at compile time, DUB automatically downloads the latest package vibe.d #!/usr/bin/rdmd
This command indicates that the file will be compiled automatically at the time of execution using the RDMD utility from the DMD package.
chmod 775
In addition, the specified example in the file generated automatically, you can delete and paste this code import vibe.d; import std.file; void image(HTTPServerRequest req, HTTPServerResponse res) { auto file = format("./public/images/%s", req.params["f"]); if(exists(file)) { auto image = cast(ubyte[]) read(file); res.writeBody(image,"image"); } else { res.writeBody("Not Found","text/plain"); } } void css(HTTPServerRequest req, HTTPServerResponse res) { auto css = readText(format("./public/css/%s", req.params["f"])); res.writeBody(css,"text/css"); } void index_req(HTTPServerRequest req, HTTPServerResponse res) { auto request = req.params["r"]; res.renderCompat!("index.dt", HTTPServerRequest, "req",string,"title")(req,request); } void index(HTTPServerRequest req, HTTPServerResponse res) { res.renderCompat!("index.dt", HTTPServerRequest, "req")(req); } shared static this() { auto router = new URLRouter; router.get("/:r",&index_req); router.get("/", &index); router.get("/css/:f",&css); router.get("/images/:f",&image); auto settings = new HTTPServerSettings; settings.port = 8080; listenHTTP(settings, router); }
!!! 5 html head title Example page body block body
and index.dt
extends layout block body h1 Example page - Home p Hello, World!
This is a template engine. How to convert your pages is described here , and an automatic converter is here .
$ cd /home/< /projects/< > $ dub
If everything is correct, the following text should appear on the screen:
Checking dependencies in '/home/< >/Projects/< >' Building configuration "application", build type debug Running dmd (compile)... Compiling diet template 'index.dt' (compat)... Compiling diet template 'index.dt' (compat)... Linking... Running /tmp/dub/1994091216/< >... Listening for HTTP requests on :::8080 Failed to listen on 0.0.0.0:8080
The last line seems to correspond to an error, but in fact it is an attempt to listen to IPv6, which is not active in my case. Only IPv4 is used.
Source: https://habr.com/ru/post/185878/