Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 20 11:16
    crimson-knight commented #1277
  • May 20 10:55
    AlexanderPankiv commented #462
  • May 20 10:31
    AlexanderPankiv commented #1277
  • May 19 20:39
    robacarp edited #1277
  • May 19 20:19
    kellytaylor removed as member
  • May 19 19:58

    robacarp on master

    Fix the correct documentation u… (compare)

  • May 19 19:58
    robacarp closed #1278
  • May 19 19:57
    robacarp commented #464
  • May 19 19:57
    robacarp closed #464
  • May 19 12:50
    crimson-knight commented #1272
  • May 19 12:37
    crimson-knight commented #1278
  • May 19 08:38
    confact commented #464
  • May 18 17:09
    robacarp commented #1276
  • May 18 17:08
    robacarp closed #1275
  • May 18 17:08
    robacarp commented #1275
  • May 18 17:07

    robacarp on master

    Updated the version number in A… (compare)

  • May 18 17:07
    robacarp closed #1280
  • May 18 17:06

    robacarp on master

    Fixing a timestamp issue to sup… (compare)

  • May 18 17:06
    robacarp closed #465
  • May 17 23:14
    crimson-knight commented #1275
Jonathan Silverman
@mixflame
i meant the question tho
@Blacksmoke16
George Dietrich
@Blacksmoke16
Request and Response objects are available to the controller as request and response methods.
Jonathan Silverman
@mixflame
worked thanks
Jonathan Silverman
@mixflame
Does anyone know if this project has a maintainer? I am offering to maintain it if it does not.
Timothy Stapleton
@retrocede
Are requests blocking in amber? eg: if two requests come in for different endpoints, will the second request have to wait for the first request to be completed before it is processed?
eg: if the endpoint triggers a large query that takes a couple of seconds to resolve
George Dietrich
@Blacksmoke16
w/o MT mode, only 1 request executes at a time, but it does leverage concurrency features such that while one request is waiting on IO, another request can execute in the mean time
all of this is built into HTTP::Server
Timothy Stapleton
@retrocede
Is there any documentation on MT mode?
I've been looking around the amber docs and haven't had much luck finding it yet
George Dietrich
@Blacksmoke16
It's a crystal thing. But is still considered experimental
Timothy Stapleton
@retrocede
ah, I see it now, thank you!
backward crazy mage puppy 36
@backward-crazy-mage-puppy-36
Hello. has anyone been able to get the new interpreter in crystal 1.3 working with an Amber project ?
_ka_
@ka_:matrix.code-feather.de
[m]
Hi together,
I'm very new to the Crystal lang and the Community and come from Ruby.
Currently I inspect some of the Web-Frameworks and found a lot in the crytal world.
I really like Amber after, I read the guides and docs and it feels very greate after the tutorial guide. :P
I hope is not a bad question here in the Chat but what is the state of Amber-Framework is it active in devlopment and is Amber somewhere in productive use, is amber a good starting point to get into the web-dev in crystal?
Sry for so many question, i try to find a web-dev starting point in the crystal lang world. 🙂
tekanic
@tekanic
Newbie Amber/Crystal user here. Can someone point me in the right direction? How do I create a variable in a pipe that I can reference in a controller? For instance, if I want to have an api where I set a batch_size and offset in a http header, and then I create a pipe to read the header. How do I store that info and reference it in a controller. Please help. I'm lost.
tekanic
@tekanic
Figured this out. To pass variables from a pipe to a controller you use: context.params["param_name"] = value
Timothy Stapleton
@retrocede
Is there any recommended approach or library for doing dependency injection in amber?
George Dietrich
@Blacksmoke16

DI isn't a super common thing in Ruby and by extension Crystal. However, there are some libs that support it. Probably not going to be easy to make Amber aware of/use it tho.

Can checkout https://github.com/veelenga/awesome-crystal#dependency-injection and https://forum.crystal-lang.org/t/dependency-injection-in-crystal/3477

Timothy Stapleton
@retrocede
thanks!
tekanic
@tekanic
I have an endpoint that stores some information for logging purposes. Part of the log requires that I save the raw request request body. When I do this the entry that gets saved into the db is "#<HTTP::FixedLengthContent:0x10d006690>". How do I prevent this and get the actual request body? Any help would be appreciated. Thank you!
George Dietrich
@Blacksmoke16
.gets_to_end prop
prob*
tekanic
@tekanic
I tried that but it saved a blank string to the db record.
George Dietrich
@Blacksmoke16
does .rewind work?
then .gets_to_end
George Dietrich
@Blacksmoke16
iirc request body is a stream, so cant really rewind/access it more than once
depending on how you have things implemented, could maybe leverage a https://crystal-lang.org/api/master/IO/MultiWriter.html to an IO::Memory that you could attach to the log record
tekanic
@tekanic
So I tried request.body.not_nil!.rewind.gets_to_end.to_s and when I hit the endpoint it gives a "can't rewind" error. But when I also try request.body.not_nil!.gets_to_end.to_s I get an empty string.
George Dietrich
@Blacksmoke16
okay yea thats what i thought, you'll have to save it when you're reading it the first time
tekanic
@tekanic
I seem to have lost my marbles.... ; ). Problem solved. It appears that the Amber Framework has a parameter "_json" that contains the raw json object. This is what I was looking for. Thanks for brainstorming with me George!
George Dietrich
@Blacksmoke16
:thumbsup:
veremitas
@veremitas
Hey just created my first amber app and was wondering Granite vs Jennifer. What are the differences ?
1 reply
tekanic
@tekanic
Does anyone have a JWT pipe example they are willing to share? Looked in the amber documentation but couldn't find one. Thanks!
Damian Hamill
@damianham
#pipes/authenticate_jwt.cr

class HTTP::Server::Context
  property current_user : User?
end

class AuthenticateJWT < Amber::Pipe::Base
  PUBLIC_PATHS = ["/", "/signin",  "/session", 
    "/signup", "/registration",  "/register"]

  # add the regular expressions of paths that have public access
  REGEX_PATHS = [
    %r(/categories(/\d+)?$/),
    %r(/products(/\d+)?$/),
    %r(/comments(/\d+)?$/),
    %r(/support/.*$/),
   ]

  def call(context)
    token = context.params["token"]? || context.request.headers["x-jwt-token"]?
    if token 
      payload, header = JWT.decode(token, Amber.settings.secret_key_base, JWT::Algorithm::HS256)
      user = User.find_by(email: payload["email"].to_s) unless payload["email"]?.nil?
    elsif user_id = context.session["user_id"]?
      user = User.find user_id
    end

    if user
      context.current_user = user

      if context.request.path.starts_with?("/admin") && ! user.is_admin? 
        context.flash[:warning] = "Access forbidden"
        context.response.headers.add "Location", "/"
        context.response.status_code = 302
      else
          call_next(context)
      end

    else
      return call_next(context) if public_path?(context.request.path, context.session["user_id"]?)
      context.flash[:warning] = "Please Sign In"
      context.response.headers.add "Location", "/signin"
      context.response.status_code = 302
    end
  end

  private def public_path?(path, user_id)
    return true if PUBLIC_PATHS.includes?(path)

    # Different strategies can be used to determine if a path is public
    # Example, if /admin/* paths are the only private paths
    # return false if path.starts_with?("/admin")
    #
    # Example, if only a few private paths exist
    # return false if ["/secret", "/super/secret", "/private"].includes?(path)

    REGEX_PATHS.count { |r| r.match(path) } > 0
  end
end
3 replies
backward crazy mage puppy 36
@backward-crazy-mage-puppy-36
If anyone has figured out how to require amber application in the new crystal interpreter please let me know. Thanks.
Lewis E. Bogan
@lebogan
I am missing something! Started the pet-tracker tutorial app and even though it compiles, there are no images rendered on the main page. Crystal 1.3.2 and Amber master branch. Webpack and nodejs are installed. The console shows 3 404 errors. What am I missing, please?
493 verbose stack Error: ENOENT: no such file or directory, open '/home/vagrant/projects/sandbox/web_stuff/pet-tracker/node_modules/globule/node_modules/minimatch/package.json.2996395629'
494 verbose cwd /home/vagrant/projects/sandbox/web_stuff/pet-tracker
495 verbose Linux 5.4.0-104-generic
496 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "--loglevel=error"
497 verbose node v10.19.0
498 verbose npm v6.14.4
499 error code ENOENT
500 error syscall open
501 error path /home/vagrant/projects/sandbox/web_stuff/pet-tracker/node_modules/globule/node_modules/minimatch/package.json.2996395629
502 error errno -2
503 error enoent ENOENT: no such file or directory, open '/home/vagrant/projects/sandbox/web_stuff/pet-tracker/node_modules/globule/node_modules/minimatch/package.json.2996395629'
504 error enoent This is related to npm not being able to find a file.
505 verbose exit [ -2, true ]
Damian Hamill
@damianham
@lebogan in Amber there is none of that wierd assets voodo that exists in Rails. Images would exist in public/images for example and you would reference them in web pages with somethinh like <img src="/images/myimage.png">
Lewis E. Bogan
@lebogan
@damianham isn't there supposed to be some rendered images out of the box? I'm not getting the web page shown in the documentation, just raw html. Maybe I need to install node and webpack differently?
Damian Hamill
@damianham
check the content type of the response in the browser dev tools is text/html
Mugirase Emmanuel
@descholar-ceo

Hello here, today is my first day trying out amberframework, but I have issues with installing it, on this command make install I am getting an error which is: cp: cannot create regular file '/usr/local/bin/amber': Permission denied

Any help here?

Damian Hamill
@damianham
look at the Docker section in the amber documentation and go that route. This does not just apply to Amber, this applies to almost everything with software engineering. Run everything in a docker comtainer, the frontend, backend database, redis etc. everything.
Mugirase Emmanuel
@descholar-ceo
Great, thank you
InfRandomness
@InfRandomness

Hi everyone, I'm new to crystal and I want to use amber for my project, only, I'm having some troubles running the getting started guide (https://docs.amberframework.org/amber/guides/installation)

https://www.toptal.com/developers/hastebin/epodaculil.rust

Damian Hamill
@damianham
Lewis E. Bogan
@lebogan
Try as I might, I still can't amber to work. Using docker, I get:
Building migrate
Step 1/7 : FROM amberframework/amber:1.0.0rc2
Service 'migrate' failed to build: manifest for amberframework/amber:1.0.0rc2 not found: manifest unknown: manifest unknown
I am using Crystal 1.3.2.
Mauricio
@banduk
Hey guys, is it possible to declare an uuid primary_key using jennifer?
I tried many ways but none of them worked
Jonathan Silverman
@mixflame
How do I remove the dependency on Sqlite from the amber crystal heroku build?
Seth T.
@crimson-knight
FWIW we created a discord to make it easier to chat with the community: https://discord.gg/vwvP5zakSn