Giter VIP home page Giter VIP logo

weblink's Introduction

weblink

WebLink

Linking Hashlink and other targets to the role of a webserver.

class Main {
    function main() {
        var app = new weblink.Weblink();
        app.get(function(request,response)
        {
            response.send("HELLO WORLD");
        });
        app.listen(2000);
    }
}

Features

  • Uses libuv
  • Minimal and concise with express lib in mind
  • No dependencies, and easy integration
  • Extremely fast, roughly 4x faster than Fastify with big data, and 2x with small Benchmark

Getting Started

Install dev version:

haxelib git weblink https://github.com/PXshadow/weblink

Include in build.hxml

-lib weblink

Targets

requires libuv (asys in the future)

  • hashlink (uses libuv)
  • more targets in the future using asys

Benchmark

Supported

  • methods
    • GET
    • POST
    • OPTIONS
    • HEAD
    • PUT
  • encoding
    • gzip
    • compress
    • deflate
    • br
  • caching
    • age
    • expires
  • security
  • extra
    • content type
    • bytes (png image for instance)
    • redirects
    • serve web content (files ex: html/images/sounds)
    • connection public ip (haxe 4.2)
    • projection (a type with certain attributes of another type, useful to send only some data)

Contributing

  1. Fork

  2. Clone and setup

  3. Configure VSCode :

    Add that in .vscode/launch.json :

    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "HashLink (launch)",
                "request": "launch",
                "type": "hl",
                "cwd": "${workspaceFolder}",
                "preLaunchTask": {
                    "type": "haxe",
                    "args": "active configuration"
                }
            },
            {
                "name": "HashLink (attach)",
                "request": "attach",
                "port": 6112,
                "type": "hl",
                "cwd": "${workspaceFolder}",
                "preLaunchTask": {
                    "type": "haxe",
                    "args": "active configuration"
                }
            }
        ]
    }
    
  4. Develop (and press F5 to launch hashlink)

  5. Pull request

weblink's People

Contributors

frixuu avatar klabz avatar neokeld avatar poklj avatar pxshadow 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

weblink's Issues

/path/:param

Is this format supported?

I do not see the param field in the Request object, I was unsuccesfull as well in finding it in the source

Busy waiting (100%) cpu usage

My current usage of hashlink is like this

var app = new weblink.Weblink();
app.get("/",(req,res)->res.send("OK"));
app.listen(799, false);
         var t=new Timer(60_000);
            t.run=function() {
                trace("dummy function to keep thread alive");
            }

If I am not passing the second parameter to listen, then hashlink will eat up a whole CPU core, by not using the blocking parameter I need to run an alternative blocker for example a timer to keep the event loop running.

The logic below is fine, assuming that MainLoop.tick has some usefull work, if this is not the case then it is just a no-op most of CPU time will be consumed by the update function, given that a webserver event loop should never block on IO I am logically stuck

public function update(blocking:Bool = true) {
		do {
			@:privateAccess MainLoop.tick(); // for timers
			loop.run(NoWait);
		} while (running && blocking);
	}

Pheraps waiting on an abandoned sys.thread.Lock(), empty deque, or double locking a mutex would be a better approach of blocking.

Thanks

Hosting a basic html page

I'm trying to host a super simple html page:

<html>
<body>
<h1>Hello</h1>
<img src="picture.jpg" />
</body>
</html>

The image is always broken, and the page doesnt stop loading.. but if i open the image link it in a new browser tab it works fine. Also, if refreshing the same image many times in a tab it will sometimes just not load..
Is this somehow related to requesting multiple files? Any way to work around it?

var app = new Weblink();
app.serve("/","d:/files_root");
app.listen(2000);

Contributing - Add a section to README

Perhaps something like this could be added to the readme?

### Contributing

1. Fork
2. Clone and setup
3. Configure VSCode :
    Add that in .vscode/launch.json : 
    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "HashLink (launch)",
                "request": "launch",
                "type": "hl",
                "cwd": "${workspaceFolder}",
                "preLaunchTask": {
                    "type": "haxe",
                    "args": "active configuration"
                }
            },
            {
                "name": "HashLink (attach)",
                "request": "attach",
                "port": 6112,
                "type": "hl",
                "cwd": "${workspaceFolder}",
                "preLaunchTask": {
                    "type": "haxe",
                    "args": "active configuration"
                }
            }
        ]
    }
4. Develop (and press F5 to launch hashlink)
5. Pull request

Add path management

Route HTTP requests to a path like /path or /another for GET, POST, PUT and HEAD requests.
We will do it with an Haxe Map to have near constant time function and middleware access.

Benchmarks

Hi!
I found this benchmarks for Fastify https://github.com/fastify/benchmarks , where requests / s are 32 912.4
On your test is about 17 000 - 22 000 r/s . Is there something different in the tests or you using different version of Fastify ?
I'm also wondering about comparison between weblink and Tomcat . Is it will be possible ?

Default Response Mime Type

The default mime type of the response is text/text.
When a dev try for the first time weblink, he sees that on Firefox :
before
It would be more user friendly with a text/html :
after

express compatiablity, early exit, streaming responses

I found a few diverts from node express, I wonder what was the design desicion, maybe this issue could be a place to discuss their need and usage.

While working on my cors PR I found that there is no way to signal in middleware that I am done processing and stop the workflow this might be usefull to restrict users, for preflight requests etc.

In node express there is the optional next callback that could be used to asynchronous signal that it is time for the next middleware, so we have the choice to end the response and never call it.
We could negate the workflow and give a response.end method to positivly signal to stop processing rules, to get the same effect, the express way is a benefit for async workflows.

Also I see that res.end is private, and res.send is calling end implicitally from sendBytes, I am happy with this desicion, as it was very common in express to forget to res.end (in try catch) and than cause the machine to exhusted all tcp connections, but on the other hand this is forcing us to keep in RAM the whole response while acummelating, (and need to use a StringBuf for efficient concatenation).

We can also solve this one with negetive logic, by giving an option to turn off implicit ending, or adding a res.write that doesn't close the connection.

Implementing compability

Hi!
I found your project very interesting and useful, but i have a questions about your vision of the weblink.
Did you make it api compatible with nodejs http-server or similar to fastify framework?

Add ability to have parameter in the query string To GET

if you register a GET like this
server.get("/hello", handler);

then calling this with a query string like this:
http://localhost:8080/hello?name=User

will result in a 404 as the pathNotFound function will be called.
Is there a way around this?

res.send is hanging, but when client is closing connection getting Eof error

Hi

I see great future for the weblink project, and trying to grasp it.

I am used to a pattern in express js that if I do not have the response immediately, or the response isn't a direct result from the request, than I am storing the res object in a global hashmap along with the ID, and when the responding routine would like to respond later in time, than the correct res is being looked up and used.
I have another timeout routine that is periodically looping all responses and closing up the idle reses.

      public function respond_to(msg,id){
  
          try {
              var res=messages.get(id);
              trace("responding");
              if (res==null){
                  trace("respond not found, returning");
                  return;
              }
              res.send(msg);
              //res.socket.close(); 
              messages.remove(id);
          } catch(ex){
              trace("Failed to respond, the connection is maybe closed",ex);
          }
      }

I am trying to implement it in weblink and I sometimes am getting the following result, res.send is hanging, but when client is closing the connection it gets an Eof error, this was the most common error.

I've also had errors like hl: ./src/unix/stream.c:951: uv__write_callbacks: Assertion `uv__has_active_reqs(stream->loop)' failed.
Aborted (core dumped)

I wonder if some pointers are being cleaned up after the route handler is being finished?

Not sure that the source of the issue is in weblink, it could be hashlink, libuv or GC related, ut as I am out of ideas on how to continue I would like to discuss it here as other weblink users might stumble into the same idiotic situation.

Thanks for any help

Add a logo

The project should have a logo to enhance visibility.

Add a middleware for compression

Add a minimal middleware (like in express), at router level (for GET routes) to compress responses.
It sets Content-Encoding to deflate in headers.
The compression is based on haxe.zip.Compress.
With hl runtime, it uses Zlib.

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.