Can I (alternatively) set the value of RUCKSACK_MODE at compile time, with :
crystal build ./src/rucksack.cr --define RUCKSACK_MODE=0
require "http/server"
require "rucksack"
RUCKSACK_MODE = 1
# Archiving mode
p "RUCKSACK_MODE = #{RUCKSACK_MODE}"
# local server set and run:
server = HTTP::Server.new do |context|
path = context.request.path
path = "/index.html" if path == "/"
path = "./webroot#{path}"
begin
rucksack(path).read(context.response.output)
rescue Rucksack::FileNotFound
context.response.status = HTTP::Status.new(404)
context.response.print "404 not found :("
end
end
address = server.bind_tcp 8080
puts "Listening on http://#{address}"
server.listen
# Set the local dir:
{% for name in `find ./webroot -type f`.split('\n') %}
rucksack({{name}})
{% end %}
Probably be a good use case for an ENV var. RUCKSACK_MODE=0 ./rucksack. Tho you will have to convert it to the proper type as it’ll always be a String.
It could either be something that controls the value at compile time, or runtime depending on when you access the value of the ENV var. For example given a program like: