vibe.d and my first web service

Mr. Backup goldnuget at email.cz
Sat Jul 18 09:10:04 UTC 2020


Hello,

I wanted to create simple web service to start learning more 
about D lang and compare with another languages. I have used "dub 
init -t vibe.d" to create basic example:

import vibe.vibe;

void main()
{
	auto settings = new HTTPServerSettings;
	settings.port = 8080;
	settings.bindAddresses = ["::1", "127.0.0.1"];
	listenHTTP(settings, &hello);

	logInfo("Please open http://127.0.0.1:8080/ in your browser.");
	runApplication();
}

void hello(HTTPServerRequest req, HTTPServerResponse res)
{
	res.writeBody("Hello, World!");
}



I started the program with "dub" command and everything worked as 
I expected. Except that there were a lot "deprecation" warnings 
and long time to compile.But when I exit the service by ctrl + c 
and start again the program cannot start again with error message:

Failed to listen on ::1:8080
Failed to listen on 127.0.0.1:8080
Failed to listen for incoming HTTP connections on any of the 
supplied interfaces.

or

leaking eventcore driver because there are still active handles


Probably the application was terminated incorrectly. What should 
I do to ensure that the application closes properly?

Thank you in advance


More information about the Digitalmars-d-learn mailing list