Giter VIP home page Giter VIP logo

mod-web-server's Introduction

Web Server

This is a simple example web server which efficiently serves files from the file system.

It can also be configured to act as an event bus bridge - bridging the server side event bus to client side JavaScript.

Name

The module name is web-server.

Configuration

The web-server configuration is as follows:

{
    "web_root": <web_root>,
    "index_page": <index_page>,
    "host": <host>,
    "port": <port>,
    "static_files": <static_files>,
    "route_matcher": <route_matcher>,
    "gzip_files": <gzip_files>,

    "ssl": <ssl>,
    "key_store_password": <key_store_password>,
    "key_store_path": <key_store_path>,

    "bridge": <bridge>,
    "inbound_permitted": <inbound_permitted>,
    "outbound_permitted": <outbound_permitted>,
    "sjs_config": <sjs_config>,
    "auth_timeout": <auth_timeout>,
    "auth_address": <auth_address>
}
  • web_root. This is the root directory from where files will be served. Anything that you place here or in sub directories will be externally accessible. Default is web.
  • index_page. The page to serve when the root / is requested. Default is index.html.
  • host. The host or ip address to listen at for connections. 0.0.0.0 means listen at all available addresses. Default is 0.0.0.0.
  • port. The port to listen at for connections. Default is 80.
  • static_files. Should the server serve static files? Default is true.
  • route_matcher. Should the server execute your defined RouteMatcher? Default is false.
  • gzip_files. Should the server serve pre-compressed files? true: check file "fileName.gz", and send it back, if not found, then fallback to "fileName". false: send back "fileName", do not check "fileName.gz" unnecessarily. Default is false.
  • ssl. Should the server use https as a protocol? Default is false.
  • key_store_password. Password of Java keystore which holds the server certificate. Only used if ssl is true. Default is wibble.
  • key_store_path. Path to keystore which holds the server certificate. Default is server-keystore.jks. Only used if ssl is true. Don't put the keystore under your webroot!.
  • bridge. Should the server also act as an event bus bridge. This is used when you want to bridge the event bus into client side JavaScript. Default is false.
  • inbound_permitted. This is an array of JSON objects representing the inbound permitted matches on the bridge. Only used if bridge is true. See the core manual for a full description of what these are. Defaults to [].
  • outbound_permitted. This is an array of JSON objects representing the outbound permitted matches on the bridge. Only used if bridge is true. See the core manual for a full description of what these are. Defaults to [].
  • sjs_config. This is a JSON object representing the configuration of the SockJS bridging application. You'd normally use this for specifying the url at which SockJS will connect to bridge from client side JS to the server. Only used if bridge is true. Default to {"prefix": "/eventbus"}.
  • auth_timeout. The bridge can also cache authorisations. This determines how long the bridge will cache one for. Default value is five minutes.
  • auth_address. The bridge can also call an authorisation manager to do authorisation. This is the address to which it will send authorisation messages. Default value is vertx.basicauthmanager.authorise.

Examples

Here are some examples:

Simple static file web server

This serves files from the web directory

{
    "host": mycompany.com
}

Simple https server

{
    "host": mycompany.com,
    "ssl": true,
    "key_store_path": "mycert.jks",
    "key_store_password": "sausages"
}

Event bus bridge

Pure event bus bridge that doesn't serve static files

{
   "host": "bridgeserver.mycompany.com",
   "static_files": false,
   "bridge": true,
   "inbound_permitted": [{"address":"myservice"}],
   "outbound_permitted": [{"address":"topic.foo"}]
}

mod-web-server's People

Contributors

arsenyyankovsky avatar ottoallmendinger avatar patoi avatar pidster avatar purplefox avatar tigeba avatar vietj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mod-web-server's Issues

[FEATURE REQUEST] Clientside Eventbus like lib

Hi,

I'm wondering why the web-server Module does not ship with a client side eventbus(bridge) implementation.

In my opinion it would be very nice if it would be possible to write client side javascript code, just like backend vertices and let them communicate with each other over the eventbusbridge with pre configured message addresses.

Any Arguments against this?

I think, otherwise every vert-x webapp would require implementing an eventbusbridge client on its own

generated ETag header value is invalid

According to http://tools.ietf.org/html/rfc7232#section-2.3 an ETag header has the format:

ETag       = entity-tag

     entity-tag = [ weak ] opaque-tag
     weak       = %x57.2F ; "W/", case-sensitive
     opaque-tag = DQUOTE *etagc DQUOTE
     etagc      = %x21 / %x23-7E / obs-text
                ; VCHAR except double quotes, plus obs-text

Ie. the tag has to be wrapped in double quotes.

The StaticFileHandler generates ETags without those quotes. Found using the REDbot tool, which complains thusly:

  • The etag header's syntax isn't valid.

    The value for this header doesn't conform to its specified syntax; see
    its definition for more information.

StaticFileHandler with cache throws java.nio.file.NoSuchFileException

Hi,
I am using StaticFileHandler in my application (to serve static content), like this:

vertx.createHttpServer().websocketHandler(socket -> {
[...]
})
.requestHandler(new StaticFileHandler(vertx, "...path..."))
.listen(config.getHttpPort());

When webapp requests a document which does not exist, the StaticFileHandler throws an exception and browser waits forever:

SEVERE: Exception in Java verticle
java.lang.IllegalStateException: Failed to check file: java.nio.file.NoSuchFileException: ...path...
    at org.vertx.mods.web.StaticFileHandler.handle(StaticFileHandler.java:184)
    at org.vertx.mods.web.StaticFileHandler.handle(StaticFileHandler.java:37)
    at org.vertx.java.core.http.impl.ServerConnection.handleRequest(ServerConnection.java:180)
[...]

The problem does not exist when caching is disabled. My workaround is this:

.requestHandler(new StaticFileHandler(vertx, "...path...") {
            @Override
            public void handle(HttpServerRequest req) {
                try {super.handle(req);} catch (Exception e) {
                    req.response().setStatusCode(404).setStatusMessage("").end();
                }
            }
        }).listen(config.getHttpPort());

It does look like a bug to me, doesn't it?

Refactor tests

I notice a lot of duplication in the tests - e.g. most (all?) are calling container.deployModule to deploy the module, this can be added to the start code.

generated Last-modified header value uses the wrong timezone

The StaticFileHandler generates Last-Modified headers with the timezone set to the current system's timezone.

It should use GMT as defined by http://tools.ietf.org/html/rfc2616#section-3.3

HTTP/1.1 200 OK
last-modified: Thu, 18 Dec 2014 11:21:17 CET
...

REDbot complains again:

  • The last-modified header's value isn't a valid date.

    HTTP dates have very specific syntax, and sending an invalid date can
    cause a number of problems, especially around caching. Common problems
    include sending "1 May" instead of "01 May" (the month is a fixed-
    width field), and sending a date in a timezone other than GMT. See the
    HTTP specification for more information.

web-server ignores port configuration and listens on default 80

I'm a vert.x newb but I'm quite sure of it, you may reproduce it on vertx-examples/src/modules/groovy/webapp/mods/io.vertxexample-web-app1.0/App.groovy

I cloned 302eab21331fc07399476fc335c62b5b804ae38d

It ignores port: 8080 and listens on 80...

I used vert.x-2.1RC3.tar.gz

webserver in vertex not working

The webserver is not starting in vertx. I have put the below code in server.rb file

require "vertx"

web_server_conf = {

'port' => 8080,

'host' => 'localhost'

}

# Start the web server, with the config we defined above

Vertx.deploy_verticle('mod-web-server', web_server_conf)

require "vertx"
include Vertx
@server = NetServer.new.connect_handler { |socket|
Pump.new(socket, socket).start
}.listen(8080, 'localhost')

When i use "vertx run server.rb" the cursor goes in the next line and then nothing happens. Even localhost:8080 doesn't work. Tried both, commented and uncommented code. Can some body help me please!!!

Vertx 3.0 support

Hi,

Does this module work with vertx 3.0 ? How can we server static web files (react js) from vertx server ? Can we use this plugin for that..

Thank you

Reference Error: vertx not defined

I have downloaded a clients project which is build using vert.x. Now when i am running the server.js file, it throws an error

org.mozilla.javascript.EcmaError: ReferenceError: "vert" is not defined. (vendor/yaml/yaml.js#390)

The yaml.js file contains the code as

// Handle vertx case
if (vertx){
this.YAML = YAML;
}

Please help me as i am new to this.

Unit tests break with millisecond last modified precision

While running the integration tests if the requested file has a last modified date with millisecond precision, something like this happens:

org.vertx.mods.test.integration.java.WebServerHeadersTest > testEtagIfUnModifiedSince STANDARD_ERROR
    java.lang.AssertionError: expected:<200> but was:<412>
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.failNotEquals(Assert.java:743)
        at org.junit.Assert.assertEquals(Assert.java:118)
        at org.junit.Assert.assertEquals(Assert.java:555)
        at org.junit.Assert.assertEquals(Assert.java:542)
        at org.vertx.testtools.VertxAssert.assertEquals(VertxAssert.java:102)
        at org.vertx.mods.test.integration.java.WebServerHeadersTest$7$1$1.handle(WebServerHeadersTest.java:260)
        at org.vertx.mods.test.integration.java.WebServerHeadersTest$7$1$1.handle(WebServerHeadersTest.java:257)
        at org.vertx.java.core.http.impl.DefaultHttpClientRequest.handleResponse(DefaultHttpClientRequest.java:283)
        at org.vertx.java.core.http.impl.ClientConnection.handleResponse(ClientConnection.java:279)
        at org.vertx.java.core.http.impl.DefaultHttpClient$ClientHandler.doMessageReceived(DefaultHttpClient.java:672)
        at org.vertx.java.core.http.impl.DefaultHttpClient$ClientHandler.doMessageReceived(DefaultHttpClient.java:652)
        at org.vertx.java.core.http.impl.VertxHttpHandler.channelRead(VertxHttpHandler.java:60)
        at org.vertx.java.core.net.impl.VertxHandler.channelRead(VertxHandler.java:156)
        at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
        at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:173)
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:148)
        at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
        at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:101)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:485)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
        at java.lang.Thread.run(Thread.java:722)

org.vertx.mods.test.integration.java.WebServerHeadersTest > testEtagIfUnModifiedSince FAILED
    java.lang.AssertionError: expected:<200> but was:<412>

org.vertx.mods.test.integration.java.WebServerHeadersTest > testEtagIfModifiedSince STANDARD_OUT
    Starting test: testEtagIfModifiedSince

org.vertx.mods.test.integration.java.WebServerHeadersTest > testEtagIfModifiedSince STANDARD_ERROR
    java.lang.AssertionError: expected:<304> but was:<200>
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.failNotEquals(Assert.java:743)
        at org.junit.Assert.assertEquals(Assert.java:118)
        at org.junit.Assert.assertEquals(Assert.java:555)
        at org.junit.Assert.assertEquals(Assert.java:542)
        at org.vertx.testtools.VertxAssert.assertEquals(VertxAssert.java:102)
        at org.vertx.mods.test.integration.java.WebServerHeadersTest$6$1$1.handle(WebServerHeadersTest.java:217)
        at org.vertx.mods.test.integration.java.WebServerHeadersTest$6$1$1.handle(WebServerHeadersTest.java:214)
        at org.vertx.java.core.http.impl.DefaultHttpClientRequest.handleResponse(DefaultHttpClientRequest.java:283)
        at org.vertx.java.core.http.impl.ClientConnection.handleResponse(ClientConnection.java:279)
        at org.vertx.java.core.http.impl.DefaultHttpClient$ClientHandler.doMessageReceived(DefaultHttpClient.java:672)
        at org.vertx.java.core.http.impl.DefaultHttpClient$ClientHandler.doMessageReceived(DefaultHttpClient.java:652)
        at org.vertx.java.core.http.impl.VertxHttpHandler.channelRead(VertxHttpHandler.java:60)
        at org.vertx.java.core.net.impl.VertxHandler.channelRead(VertxHandler.java:156)
        at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
        at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:173)
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:148)
        at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337)
        at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:101)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:485)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
        at java.lang.Thread.run(Thread.java:722)

org.vertx.mods.test.integration.java.WebServerHeadersTest > testEtagIfModifiedSince FAILED
    java.lang.AssertionError: expected:<304> but was:<200>

This occurs because we are using the file system to return the file timestamp, which can have millisecond precision (at least on Windows it has), and comparing/passing it to the HTTP headers, which follow the "EEE, dd MMM yyyy HH:mm:ss zzz" format. As this format does not include milliseconds, we are losing precision during the round trip. When, on the client (e.g. the failing test methods above), we use the received "last-modified" header to enable cache behaviour (tested by "If-Modified-Since" and "If-Unmodified-Since" on the tests), we may get unexpected results (like 412 and 304 error codes produced by StaticFileHandler) if our "last-modified" header (second precision) is actually behind the real "last-modified" file timestamp (millisecond precision).

If we are not using "webserver.fileProps.modified" for anything other than caching HTTP requested resources, I would suggest a small change to the checkCacheOrFileSystem method, in order to decrease our precision to the same level as the HTTP headers format we are using. As we are only able to the get the second precision for the request, I don't see any reason why our cache should use a more accurate representation (in the case it is effectively true that the map is not being used for anything else).

  private long checkCacheOrFileSystem(String fileName) {

    if (filePropsModified.containsKey(fileName)) {
      return filePropsModified.get(fileName);
    }

    FileProps fileProps = fileSystem.propsSync(fileName);

    // HTTP headers only have second precision, not millisecond
    long lastModified = fileProps.lastModifiedTime().getTime() / 1000 * 1000;

    filePropsModified.put(fileName, lastModified);

    return lastModified;
  }

Add url mapping mechanism for static files.

I think it will be nice to allow users to define url mappings for static files in configuration. The idea is that you can configure server to resolve posts.html file by url /posts or /posts/page/3. User can achieve that functionality right now using StaticFileHandler with his own RouteMatcher, but I think it's nice to have it out-of-box.

support running the web server an a random port

Setting the port to 0 in the config, starts the server on a random port.

Alas, it seems there is no way to retrieve the port where the service was eventually bound to, currently.

It would be nice if one could use a shared map, say "webserver.config", to query that information (and more?) from the web-server. That would be especially useful in test cases where you don't want to depend on a static port setting.

runMod not working

runMod failed on line 144

No such property: reverceLoaderOrder for class: org.vertx.java.platform.impl.ModuleClassLoader

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.