Coder Social home page Coder Social logo

artanis's People

Contributors

jhass avatar trapped avatar ysbaddaden 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

artanis's Issues

Use a tree for routing

The idea is to generate a tree of routes, using the different segments for each node, which may either be a static string (eg: posts) or a variable (eg: :id) with or without a regexp match (eg: /^\d+$/) or always matching (eg: *path).

Resolving a route should then be (almost) constant time, and not tied to wherever the route is defined first or last. Currently, hitting the first matching route is fast (we run a single regular expression) but matching the last route is slow (we run N regular expressions, where N can grow quickly). We can define the most important routes first, and the less used ones last, but what about when the route doesn't exist? A potential DDoS is to hit long URI, so each regexp is slow, and that doesn't match.

I don't know what will happen to the before and after blocks. Maybe they can just become attributes to the tree node, and run whenever the node matches.

Broken test: test_flushes_body_to_io

def test_flushes_body_to_io
call("GET", "/custom", io = MemoryIO.new)
body = io.to_s
assert_match /LAYOUT: CUSTOM/, body
assert_match /message: custom/, body
end

[brian@orville artanis]$ make
crystal test/*_test.cr
................F..

Finished in 00:00:00.0068770, 145.412 runs/s

  1. Failure:
    Artanis::RenderTest#test_flushes_body_to_io [test/render_test.cr:44]:
    Expected /LAYOUT: CUSTOM/ to match: ""

19 tests, 1 failures, 0 errors, 0 skips
Makefile:6: recipe for target 'test' failed
make: *** [test] Error 255

views_path macro passing incorrect echo argument

Premise: there's no views folder and I'm using OSX 10.10 (zsh as shell).

require "artanis"

class App < Artanis::Application
end

The views_path macro produces this (invalid) code:

def render_-n_ecr
  render_-n_ecr {}
end

def render_-n_ecr(&block)
  String.build do |__str__|
    embed_ecr "views/-n.ecr", "__str__"
  end
end

The issue seems to be the echo -n "" part of the command, producing -n as output (I don't know whether the backtick syntax executes the command inside a shell).
I temporarily worked around the issue by using true instead of echo -n "", which fixes the issue since the output is the same.

call macro generating invalid case statement when there are no handlers defined

require "artanis"

class App < Artanis::Application
end

The call macro generates an invalid case statement:

case request.method.upcase

else
  no_such_route
end

response

Checking whether there actually are handlers defined fixes the issue:

macro def call : HTTP::Response
  {% if @type.methods.size > 0 %}
  case request.method.upcase
  {{
    @type.methods
      .map(&.name.stringify)
      .select(&.starts_with?("match_"))
      .map { |method_name| method_name.split("_")[1] }
      .uniq
      .map { |method| "when #{method}\n        call_method(#{method})" }
      .join("\n      ")
      .id
  }}
  else
    no_such_route
  end
  {% else %}
  no_such_route
  {% end %}
  response
end

Enhancement for filters before execution or after

Hello @ysbaddaden:

I discovered this dsl today, nice work. Is there any way to integrate chained filters for each macro get, post, etc?

For example a normal pattern will be to have jwt integration in a JSON api for a lot of get and post routes, and if there's a pre filter with a token verification error it should always return 403 (forbidden).

Thanks in advance,
raydf

Issue with minitest on build

Using latest shards / crystal installation.

[brian@orville artanis]$ shards
Updating https://github.com/ysbaddaden/minitest.cr.git
Using minitest (f2014c2175064e0b41bdfdc4b64f8a69b25da075)
[brian@orville artanis]$ make
crystal test/*_test.cr
Error in ./test/dsl_test.cr:1: while requiring "./test_helper"

require "./test_helper"
^

in ./test/test_helper.cr:1: while requiring "../libs/minitest/autorun"

require "../libs/minitest/autorun"
^

in ./libs/minitest/autorun.cr:1: while requiring "./minitest"

require "./minitest"
^

in ./libs/minitest/minitest.cr:5: while requiring "./minitest/test"

require "./minitest/test"
^

in ./libs/minitest/minitest/test.cr:1: while requiring "./assertions"

require "./assertions"
^

Syntax error in ./libs/minitest/minitest/assertions.cr:7: the syntax for an argument with a default value V and type T is arg : T = V

def initialize(@message = nil : String?, @Cause = nil : Exception?, @file = FILE, @line = LINE)
^

Makefile:3: recipe for target 'test' failed
make: *** [test] Error 1
[brian@orville artanis]$ crystal --version
Crystal 0.14.2 [e1af3d5](Wed Mar 23 00:03:46 UTC 2016)

Example in README doesn't work

I'm using crystal 0.17 on a debian 32 bit system and I am getting:

$ crystal run example.cr 
Error in ./example.cr:26: instantiating 'App:Class#call(HTTP::Server::Context)'

  App.call(context)
      ^~~~

in ./libs/artanis/application.cr:50: instantiating 'App#call()'

      new(context).call
                   ^~~~

in macro 'call_action' /media/disk/bentkus/Projects/crystal/artanis/libs/artanis/dsl.cr:87, line 1:

  1.       if __temp_99 = URI.unescape(request.path || "/").match(MATCH_GET__SLASH_)
  2.         __temp_100 = match_GET__SLASH_(__temp_99)
  3. 
  4.         
  5.           break unless __temp_100 == :pass
  6.         
  7.       end
  8.     

      if __temp_99 = URI.unescape(request.path || "/").match(MATCH_GET__SLASH_)
                                                             ^~~~~~~~~~~~~~~~~

undefined constant MATCH_GET__SLASH_

I haven't looked into the code yet, it was pointed out to me in the channel that this library makes use of the macro features and that I should look into it to see what is possible.

Any quick idea on why this error is thrown?

Issues building

[brian@orville artanis]$ make
crystal test/*_test.cr
Error in ./test/dsl_test.cr:1: while requiring "./test_helper"

require "./test_helper"
^

in ./test/test_helper.cr:3: while requiring "../src/artanis"

require "../src/artanis"
^

in ./src/artanis.cr:1: while requiring "./application"

require "./application"
^

in ./src/application.cr:3: while requiring "http/response": can't find file 'http/response' relative to '/data2/Projects/artanis/src'

require "http/response"
^

Makefile:3: recipe for target 'test' failed
make: *** [test] Error 1

Any ideas ?

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.