feat: ping route + controller
This commit is contained in:
@@ -0,0 +1 @@
|
||||
DATABASE_URL=./sqlite/db.sqlite
|
||||
+24
@@ -4,6 +4,18 @@ shards:
|
||||
git: https://github.com/sija/backtracer.cr.git
|
||||
version: 1.2.2
|
||||
|
||||
crecto:
|
||||
git: https://github.com/fridgerator/crecto.git
|
||||
version: 0.12.1
|
||||
|
||||
db:
|
||||
git: https://github.com/crystal-lang/crystal-db.git
|
||||
version: 0.13.1
|
||||
|
||||
dotenv:
|
||||
git: https://github.com/gdotdesign/cr-dotenv.git
|
||||
version: 0.6.0
|
||||
|
||||
exception_page:
|
||||
git: https://github.com/crystal-loot/exception_page.git
|
||||
version: 0.4.1
|
||||
@@ -12,7 +24,19 @@ shards:
|
||||
git: https://github.com/kemalcr/kemal.git
|
||||
version: 1.5.0
|
||||
|
||||
micrate:
|
||||
git: https://github.com/amberframework/micrate.git
|
||||
version: 0.3.3
|
||||
|
||||
radix:
|
||||
git: https://github.com/luislavena/radix.git
|
||||
version: 0.4.1
|
||||
|
||||
spec-kemal:
|
||||
git: https://github.com/kemalcr/spec-kemal.git
|
||||
version: 0.5.0
|
||||
|
||||
sqlite3:
|
||||
git: https://github.com/crystal-lang/crystal-sqlite3.git
|
||||
version: 0.21.0
|
||||
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
name: url-shortener
|
||||
name: pa
|
||||
version: 0.1.0
|
||||
|
||||
authors:
|
||||
- Juan Rodriguez <sjdonado@icloud.com>
|
||||
|
||||
targets:
|
||||
url-shortener:
|
||||
main: src/url-shortener.cr
|
||||
pa:
|
||||
main: src/pa.cr
|
||||
|
||||
dependencies:
|
||||
kemal:
|
||||
github: kemalcr/kemal
|
||||
sqlite3:
|
||||
github: crystal-lang/crystal-sqlite3
|
||||
crecto:
|
||||
github: fridgerator/crecto
|
||||
micrate:
|
||||
github: amberframework/micrate
|
||||
|
||||
development_dependencies:
|
||||
dotenv:
|
||||
github: gdotdesign/cr-dotenv
|
||||
spec-kemal:
|
||||
github: kemalcr/spec-kemal
|
||||
|
||||
crystal: '>= 1.12.1'
|
||||
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
require "spec"
|
||||
require "../src/url-shortener"
|
||||
require "../src/pa"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
ENV["APP_ENV"] ||= "development"
|
||||
|
||||
{% if env("APP_ENV") != "production" %}
|
||||
require "dotenv"
|
||||
Dotenv.load ".env.#{ENV["APP_ENV"]}" # File must exist in non-production!
|
||||
{% end %}
|
||||
@@ -0,0 +1,5 @@
|
||||
require "kemal"
|
||||
|
||||
Kemal.config.env = ENV["ENV"]? || "development"
|
||||
Kemal.config.port = ENV["PORT"]?.try(&.to_i) || 3000
|
||||
Kemal.config.host_binding = ENV["HOST"]? || "0.0.0.0"
|
||||
@@ -0,0 +1,10 @@
|
||||
require "../lib/controller.cr"
|
||||
|
||||
module Pa::Controllers::Ping
|
||||
class Get < Pa::Lib::BaseController
|
||||
def call(env)
|
||||
response = {"pong" => "ok"}
|
||||
response.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
module Pa::Lib
|
||||
abstract class BaseController
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
require "./config/*"
|
||||
require "./services/*"
|
||||
require "./routes"
|
||||
|
||||
error 500 { |env| {"status" => 500, "error" => "Internal Server Error"}.to_json }
|
||||
error 401 { |env| {"status" => 401, "error" => "Unauthorized"}.to_json }
|
||||
error 403 { |env| {"status" => 403, "error" => "Forbidden"}.to_json }
|
||||
error 404 { |env| {"status" => 404, "error" => "Not Found"}.to_json }
|
||||
|
||||
Kemal.run
|
||||
@@ -0,0 +1,8 @@
|
||||
require "kemal"
|
||||
require "./controllers/**"
|
||||
|
||||
module Pa
|
||||
get "/api/ping" do |env|
|
||||
Controllers::Ping::Get.new.call(env)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
require "sqlite3"
|
||||
require "crecto"
|
||||
|
||||
module Pa::Services
|
||||
class Repo
|
||||
extend Crecto::Repo
|
||||
|
||||
Query = Crecto::Repo::Query
|
||||
Multi = Crecto::Repo::Multi
|
||||
|
||||
config do |conf|
|
||||
conf.adapter = Crecto::Adapters::SQLite3
|
||||
conf.database = ENV["DATABASE_URL"]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,7 +0,0 @@
|
||||
require "kemal"
|
||||
|
||||
get "/" do
|
||||
"Hello World!"
|
||||
end
|
||||
|
||||
Kemal.run
|
||||
@@ -0,0 +1,3 @@
|
||||
module Pa
|
||||
VERSION = "0.1.0"
|
||||
end
|
||||
Reference in New Issue
Block a user