On Saturday, 1 February 2020 at 10:35:52 UTC, seany wrote:
Hi
I want to start a small server, that will be accessible form
outside. Not a huge deal right?
Not quite.
My machine: 4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09
UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
DMD : DMD64 D Compiler v2.090.0
Copyright (C) 1999-2019 by The D Language Foundation, All
Rights Reserved written by Walter Bright
Now, I try to install dub from the official repo.
Then I do
* dub init server -t vibe.d
* cd server
* dub
I hit this issue : https://github.com/dlang/dub/issues/1712
As suggested, i try to build dub from github, following:
https://github.com/dlang/dub/releases
I call ./build.d - and everything stops, and machine crashes.
I then try to install DaNode:
https://github.com/DannyArends/DaNode
It breaks with : module std.algorithm import 'mean' not found
Then I try to install the Hunt Framework. It breaks with :
basic type
expected, not foreach
Please help. I really want this issue to be resolved-
## 1. For simple server you can using hunt-http library.
Sample code:
```
import hunt.http;
void main()
{
HttpServer server = HttpServer.builder()
.setListener(8080, "0.0.0.0")
.onPost("/", (RoutingContext context) {
context.end("Hello World!");
})
.onGet("/user/:name", (RoutingContext ctx) {
string name = ctx.getRouterParameter("name");
ctx.write("Hello " ~ name);
ctx.end();
})
.build();
server.start();
}
```
## 2. For full server, you can using hunt-skeleton
(hunt-framework based):
```bash
git clone https://github.com/huntlabs/hunt-skeleton.git myproject/
cd myproject/
dub run -v
```
You can Add pages in `config/routes` , like this:
```
GET / index.index
GET /user/{name} user.detail
```
Add Controller file `controller/UserController.d` :
```
module app.controller.UserController;
import hunt.framework;
class UserController : Controller
{
mixin MakeController;
@Action
string detail(string name)
{
return "Hello " ~ name;
}
}
```
Build and run it:
```
cd myproject/
dub run -v
```
You can see it in the borwser:
```
http://localhost:8080
```