wasabifx / wasabi

An HTTP Framework
502 stars 56 forks source link

Virtual Host with built-in Wasabi web server #25

Closed bkawakami closed 9 years ago

bkawakami commented 9 years ago

I need say.. This project is amazing!

Well, when I compile my project with this:

package kotlinApi

import org.wasabi.app.AppServer

fun main(args: Array<String>){
    var server = AppServer()

    server.get("/hello", { response.send("Hello World!") })

    server.start()
}

I receive on my console:

[main] INFO org.wasabi.app.AppServer - Server starting on port 3000
[nioEventLoopGroup-3-1] INFO org.wasabi.interceptors.LoggingInterceptor - [GET] - /
[nioEventLoopGroup-3-2] INFO org.wasabi.interceptors.LoggingInterceptor - [GET] - /hello

It seems to me that the Wasabi has a built-in web server.

The default host is http://localhost:3000

How do I set up a virtual host with this built-in web server?

swishy commented 9 years ago

Great glad you find it useful,

Yes wasabi is self hosting ( built on top of Netty ) you can change the port it binds to in the configuration, in your example just add 'server.configuration.port = somevalue' before starting Wasabi ( and Netty ) are designed to build self hosting event driven applications ( web in the case of wasabi ) , can you explain your intended use case a bit more?

bkawakami commented 9 years ago

Thank you for your response Dale

And sorry for my English, I am Brazilian.

I started programming with web languages like PHP, which work on Apache.

Apache has support for virtual host. For example, locally I could direct my http://localhost:3000 to http://mylocation.dev

This is possible with the Wasabi?

And again, this project is really amazing... When I get to be more experienced I will try to contribute!

Thanks for your attention!

bkawakami commented 9 years ago

Another question, how do I return JSON in default? The default is XML, I would switch to JSON

hhariri commented 9 years ago

What do you need to do? Send back an object? As long as the serializers are configured (which by default JSON is), you just set the content type. Nothing more.

bkawakami commented 9 years ago

I try return a Hashmap, and by default I receive a XML:

server.get("/hello", {
                var x = hashMapOf(Pair("a","b"),Pair("sada","bfds"),Pair("fda","bfv"))
                response.send(x)
        })

Return

<HashMap>
<fda>bfv</fda>
<sada>bfds</sada>
<a>b</a>
</HashMap>
hhariri commented 9 years ago

What do you set as content type?

Regards, Hadi Hariri http://hadihariri.com | @hhariri

On 20 September 2015 at 21:50, Bruno Kawakami notifications@github.com wrote:

I try return a Hashmap, and by default I receive a XML:

server.get("/hello", { var x = hashMapOf(Pair("a","b"),Pair("sada","bfds"),Pair("fda","bfv")) response.send(x) })

Return

bfv bfds b

— Reply to this email directly or view it on GitHub https://github.com/hhariri/wasabi/issues/25#issuecomment-141827138.

swishy commented 9 years ago

If you already have an apache instance setup to do virtualhosting you could just bind wasabi to an IP/Port on a machine within your network and add a entry like the below to your configuration.

<VirtualHost *:80>
  ProxyPreserveHost On
  ServerName http://mylocation.dev
  ProxyPass / http://yourmachineIP:3000/
  ProxyPassReverse / http://yourmachineIP:3000
</VirtualHost>

Doing the actual virtualhosting is not something which is easily done within wasabi/netty itself.

swishy commented 9 years ago

To further @hhariri 's comment wasabi by default handles serialization based on the Accept header the client sends in. In your case you would just want to set it to 'application/json' . You can also force response content sent in your route declaration as described here:

https://github.com/hhariri/wasabi#manual

bkawakami commented 9 years ago

@swishy and @hhariri thanks for all... Everything work :)

You are the best!