RejectedSoftware Forums

Sign up

Codes are running twice?

import vibe.d;
import std.stdio;

shared static this()
{
	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.");
}


void hello(HTTPServerRequest req, HTTPServerResponse res){
	writeln("running once or twice?");
	res.writeBody("Yep you are here...");
}

I created a simple project, I noticed that things are running twice?

the console says

Please open http://127.0.0.1:8080/ in your browser
running once or twice?
running once or twice?

It is definitely running twice, why is that?

Re: Codes are running twice?

Am 16.02.2016 um 17:40 schrieb Louie Bacani Foronda:

import vibe.d;
import std.stdio;

shared static this()
{
	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.");
}


void hello(HTTPServerRequest req, HTTPServerResponse res){
	writeln("running once or twice?");
	res.writeBody("Yep you are here...");
}

I created a simple project, I noticed that things are running twice?

the console says

Please open http://127.0.0.1:8080/ in your browser
running once or twice?
running once or twice?

It is definitely running twice, why is that?

The browser is probably requesting "/favicon.ico" in addition to "/".
Try to print req.requestURL to know for sure.

Re: Codes are running twice?

On Tue, 16 Feb 2016 19:09:47 +0100, Sönke Ludwig wrote:

Am 16.02.2016 um 17:40 schrieb Louie Bacani Foronda:

import vibe.d;
import std.stdio;

shared static this()
{
	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.");
}


void hello(HTTPServerRequest req, HTTPServerResponse res){
	writeln("running once or twice?");
	res.writeBody("Yep you are here...");
}

I created a simple project, I noticed that things are running twice?

the console says

Please open http://127.0.0.1:8080/ in your browser
running once or twice?
running once or twice?

It is definitely running twice, why is that?

The browser is probably requesting "/favicon.ico" in addition to "/".
Try to print req.requestURL to know for sure.

yep it is requesting favicon.ico, any fix for this? as almost all codes runs twice because of this...

Re: Codes are running twice?

Am 17.02.2016 um 15:48 schrieb Louie Bacani Foronda:

On Tue, 16 Feb 2016 19:09:47 +0100, Sönke Ludwig wrote:

Am 16.02.2016 um 17:40 schrieb Louie Bacani Foronda:

(...)
It is definitely running twice, why is that?

The browser is probably requesting "/favicon.ico" in addition to "/".
Try to print req.requestURL to know for sure.

yep it is requesting favicon.ico, any fix for this? as almost all codes runs twice because of this...

There is no real "fix" for this, because the browser will just do that
no matter what, but you'd usually just restrict the code to run only for
a particular URL. The typical way for low-level code is to use a
URLRouter and then call router.get("/", &hello); and pass router
to listenHTTP. See also http://vibed.org/docs#http-routing.

Re: Codes are running twice?

Actually, as far as I can tell all code is running twice.

I noticed the same thing when running a project using the latest release.

To demonstrate, if I create an empty vibed project using

dub init myproject -t vibe.d

and then alter the demo Hello function to have

import std.stdio;

and

writeln("hello there");

When i run it and pull the URL, I see "hello there" twice in the console.

Looks like a bug in the request handler?

Cheers.

On Fri, 19 Feb 2016 21:00:04 +0100, Sönke Ludwig wrote:

Am 17.02.2016 um 15:48 schrieb Louie Bacani Foronda:

On Tue, 16 Feb 2016 19:09:47 +0100, Sönke Ludwig wrote:

Am 16.02.2016 um 17:40 schrieb Louie Bacani Foronda:

(...)
It is definitely running twice, why is that?

The browser is probably requesting "/favicon.ico" in addition to "/".
Try to print req.requestURL to know for sure.

yep it is requesting favicon.ico, any fix for this? as almost all codes runs twice because of this...

There is no real "fix" for this, because the browser will just do that
no matter what, but you'd usually just restrict the code to run only for
a particular URL. The typical way for low-level code is to use a
URLRouter and then call router.get("/", &hello); and pass router
to listenHTTP. See also http://vibed.org/docs#http-routing.

Re: Codes are running twice?

Note, I've tried this on both Windows and Linux / CentOS.

Cheers.

On Sat, 20 Feb 2016 23:54:30 GMT, Andrew Chapman wrote:

Actually, as far as I can tell all code is running twice.

I noticed the same thing when running a project using the latest release.

To demonstrate, if I create an empty vibed project using

dub init myproject -t vibe.d

and then alter the demo Hello function to have

import std.stdio;

and

writeln("hello there");

When i run it and pull the URL, I see "hello there" twice in the console.

Looks like a bug in the request handler?

Cheers.

On Fri, 19 Feb 2016 21:00:04 +0100, Sönke Ludwig wrote:

Am 17.02.2016 um 15:48 schrieb Louie Bacani Foronda:

On Tue, 16 Feb 2016 19:09:47 +0100, Sönke Ludwig wrote:

Am 16.02.2016 um 17:40 schrieb Louie Bacani Foronda:

(...)
It is definitely running twice, why is that?

The browser is probably requesting "/favicon.ico" in addition to "/".
Try to print req.requestURL to know for sure.

yep it is requesting favicon.ico, any fix for this? as almost all codes runs twice because of this...

There is no real "fix" for this, because the browser will just do that
no matter what, but you'd usually just restrict the code to run only for
a particular URL. The typical way for low-level code is to use a
URLRouter and then call router.get("/", &hello); and pass router
to listenHTTP. See also http://vibed.org/docs#http-routing.

Re: Codes are running twice?

Oh dear sorry ignore those last two posts! I just properly read the commends above and now understand about browser making the favicon.ico request. Will adjust to use the router correctly.

On Sat, 20 Feb 2016 23:55:39 GMT, Andrew Chapman wrote:

Note, I've tried this on both Windows and Linux / CentOS.

Cheers.

On Sat, 20 Feb 2016 23:54:30 GMT, Andrew Chapman wrote:

Actually, as far as I can tell all code is running twice.

I noticed the same thing when running a project using the latest release.

To demonstrate, if I create an empty vibed project using

dub init myproject -t vibe.d

and then alter the demo Hello function to have

import std.stdio;

and

writeln("hello there");

When i run it and pull the URL, I see "hello there" twice in the console.

Looks like a bug in the request handler?

Cheers.

On Fri, 19 Feb 2016 21:00:04 +0100, Sönke Ludwig wrote:

Am 17.02.2016 um 15:48 schrieb Louie Bacani Foronda:

On Tue, 16 Feb 2016 19:09:47 +0100, Sönke Ludwig wrote:

Am 16.02.2016 um 17:40 schrieb Louie Bacani Foronda:

(...)
It is definitely running twice, why is that?

The browser is probably requesting "/favicon.ico" in addition to "/".
Try to print req.requestURL to know for sure.

yep it is requesting favicon.ico, any fix for this? as almost all codes runs twice because of this...

There is no real "fix" for this, because the browser will just do that
no matter what, but you'd usually just restrict the code to run only for
a particular URL. The typical way for low-level code is to use a
URLRouter and then call router.get("/", &hello); and pass router
to listenHTTP. See also http://vibed.org/docs#http-routing.