Skip to content

Instantly share code, notes, and snippets.

@3zcurdia
Created April 17, 2021 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3zcurdia/bf031e288c7e09a14ee7e83a108e558b to your computer and use it in GitHub Desktop.
Save 3zcurdia/bf031e288c7e09a14ee7e83a108e558b to your computer and use it in GitHub Desktop.
Rails App under 10 lines
require 'bundler/inline'; gemfile(true) { gem 'rails', '~> 6.1.3'; gem 'puma' }
require 'rails'; require 'action_controller/railtie';
Codes = Struct.new(:id) { def to_json(args = {}) = { id: id, hex: SecureRandom.hex, iat: Time.now.utc.to_i }.to_json(args) }
class CodesApp < Rails::Application
config.secret_key_base = '4bdd3baa5f573f06c71cfb0504273e7ed1cf95858d7be6268bd1c7f800bbd03e1169e89106a9cf99541ac1b75ad4685d731723a30660c2cc66912609fd008090'
Rails.logger = Logger.new($stdout)
end
Rails.application.routes.draw { get '/:id', to: lambda { |env| [200, { 'Content-Type' => 'application/json' }, [Codes.new(env['action_dispatch.request.path_parameters'][:id]).to_json]] } }
run CodesApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment