Created
April 17, 2021 04:39
-
-
Save 3zcurdia/bf031e288c7e09a14ee7e83a108e558b to your computer and use it in GitHub Desktop.
Rails App under 10 lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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