Lucky Logo
OCTOBER 23, 2024

Lucky v1.3.0 has been released

Closing out the final quarter of 2024 with improved attack protection, better Windows compatibility, arbitrary CLI tasks, and more.

Lucky v1.3.0 has been released. This is a smaller release to fix compatibility with Crystal 1.13.x and later.

Read through the CHANGELOG for all of the changes, but we will discuss some of the highlights here.

# How to upgrade

See the UPGRADE_NOTES.

You can also view the changes using LuckyDiff.

# Here’s what’s new

# New MaximumRequestSizeHandler

This is a new handler you can add to your server middleware stack allowing you to customize the maximum size your requests should allow. This may help you to prevent your app from being attacked with extra large file sizes or payloads.

Add Lucky::MaximumRequestSizeHandler.new to your src/app_server.cr

def middleware : Array(HTTP::Handler)
  [
    Lucky::RequestIdHandler.new,
    #...
    Lucky::MaximumRequestSizeHandler.new,
    #...
  ]
end

Then add a configuration for it in config/server.cr

Lucky::MaximumRequestSizeHandler.configure do |settings|
  settings.enabled = true
  settings.max_size = 10_485_760 # 10MB
end

# More support for Windows

Our previous release 1.2.0 added the ability to install the Lucky CLI on Windows using Scoop, but booting the Lucky app still had quite a few issues.

This release has put a lot more focus in to Windows compatibility with most of the eco system shards fully working.

The following shards all now have Windows compatibility:

The final shard missing is Avram (which is mainly held back by this issue on PG), and the CLI itself which will be finalized once Avram is updated.

If you’re a developer using Windows, we would love the additional assistance. Reach out on Discord if you have questions.

# Arbitrary CLI tasks

One major issue that held Lucky back on Windows compatibility was the use of the postinstall scripts on Lucky, Carbon, and Avram. Previously, when installing these shards, they would need to run a bash script that would then precompile a few binaries for use with your app. For example, the lucky gen.secret_key task which generates a random unique key.

Aside from these bash scripts not being directly usable on Windows, there’s also been discussion that postinstall can be “harmful” and may possibly removed in a future version of Crystal. By removing the use of the postinstall, Lucky was able to do a few things:

  • Installing the shards is way faster since it no longer needs to stop and precompile several binaries
  • No more need for bash scripts to install Lucky making the installation process more portable and cross platform accessible
  • A refactor led to a new feature of arbitrary CLI tasks

You can now create a simple Crystal file script and place it in your app’s bin directory and name it lucky.your.custom.task.cr. To execute this script, just run lucky your.custom.task. You can compile this task in to a binary at any time you wish by running

crystal build --release bin/lucky.your.custom.task.cr -o bin/lucky.your.custom.task

Next time you execute this call, it’ll run the compiled version instantly.

The next release, a new lucky build command will make this easier.

# Parting words

Thank you for sticking with Lucky. While there’s many options out there to choose from, it means a lot that you’ve chosen this framework. If you’re using Lucky in production, and would like to add your application to our Awesome Lucky “built-with” section, feel free to open an issue on the Website or a PR!

# Follow and spread the word

If you haven’t already, give us a star on GitHub, and be sure to follow us on X (formerly Twitter).

Learn tips and tricks with LuckyCasts.

If you have any questions, or just want to chat, please join us on Discord.