On Thursday, 7 May 2015 at 09:27:39 UTC, Chris wrote:
On Thursday, 7 May 2015 at 08:25:30 UTC, Suliman wrote:
You're not setting a port.
add:
settings.port = 8080;
before listenHTTP();
then it'll work.
It's do not help :(
This should work, put it in your `app.d` file:
import vibe.d;
shared static this()
{
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
auto router = new URLRouter;
router.get("*", serveStaticFiles("./public/"));
listenHTTP(settings, router);
logInfo("Please open http://127.0.0.1:8080/ in your
browser.");
}
Mind you, don't forget the `.` before the forward slash in
serveStaticFiles("./public/").
Any file in the folder `public` should now be "navigate-able
to" via:
http://127.0.0.1:8080/index.html
or
http://localhost/index.html
For starters, don't make your own custom main method. Just
create a vibe.d project and paste the above code into app.d.
Later you can have a more sophisticated handling of requests.
Do this
1.
dub init suliman vibe.d
2. You might see an info message like this
Deprecated use of init type. Use --type=[vibe.d | deimos |
minimal] in future.
Successfully created an empty project in
'/home/christoph/D/vibed/Tests/suliman'.
3. Now you have a small project. Go to the folder
`suliman/source` and open the file app.d
4. Replace the whole code in there with
import vibe.d;
shared static this()
{
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
auto router = new URLRouter;
router.get("*", serveStaticFiles("./public/"));
listenHTTP(settings, router);
logInfo("Please open http://127.0.0.1:8080/ in your browser.");
}
5. Save an build the project
6. Create a file called `index.html` in the (sub)folder `public`
that is in the folder `suliman`, i.e. `suliman/public/`
7. Paste this code into it:
<html>
<p>
Hello, Suliman!
</p>
</html>
8. Save it and navigate in your browser to
http://127.0.0.1:8080/index.html
You should see "Hello, Suliman!" in your browser window now.
Hope this helped you.
C.