add remote addr

This commit is contained in:
Alexander Popov 2022-11-06 20:49:43 +00:00
parent d94f9c96da
commit e7c22b2c24
4 changed files with 32 additions and 23 deletions

View File

@ -1,15 +0,0 @@
require "kemal"
get "/" do
"Hello World!"
end
get "/ip" do |env|
env.response.content_type = "text/plain"
p! env.request.remote_address.to_s
"Hello World!"
end
Kemal.run

View File

@ -1,18 +1,18 @@
name: ips
version: 0.1.0
# authors:
# - name <email@example.com>
authors:
- Alexander Popov <iiiypuk@fastmail.fm>
# description: |
# Short description of ips
description: |
IP Services
dependencies:
kemal:
github: kemalcr/kemal
# development_dependencies:
# webmock:
# github: manastech/webmock.cr
targets:
ips:
main: src/ips.cr
# license: MIT
license: MIT-0

15
src/api/remote_addr.cr Normal file
View File

@ -0,0 +1,15 @@
require "kemal"
# Return remote user IP address
#
# Output:
# ```plain
# 127.0.0.1
# ```
get "/ip" do |env|
env.response.content_type = "text/plain"
addr = env.request.remote_address.to_s
addr.split(":")[0]
end

9
src/ips.cr Normal file
View File

@ -0,0 +1,9 @@
require "kemal"
require "./api/*"
get "/" do
"Hello World!"
end
Kemal.config.port = 3009
Kemal.run