add remote addr
This commit is contained in:
parent
d94f9c96da
commit
e7c22b2c24
15
server.cr
15
server.cr
@ -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
|
|
16
shard.yml
16
shard.yml
@ -1,18 +1,18 @@
|
|||||||
name: ips
|
name: ips
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
|
|
||||||
# authors:
|
authors:
|
||||||
# - name <email@example.com>
|
- Alexander Popov <iiiypuk@fastmail.fm>
|
||||||
|
|
||||||
# description: |
|
description: |
|
||||||
# Short description of ips
|
IP Services
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
kemal:
|
kemal:
|
||||||
github: kemalcr/kemal
|
github: kemalcr/kemal
|
||||||
|
|
||||||
# development_dependencies:
|
targets:
|
||||||
# webmock:
|
ips:
|
||||||
# github: manastech/webmock.cr
|
main: src/ips.cr
|
||||||
|
|
||||||
# license: MIT
|
license: MIT-0
|
||||||
|
15
src/api/remote_addr.cr
Normal file
15
src/api/remote_addr.cr
Normal 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
9
src/ips.cr
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
require "kemal"
|
||||||
|
require "./api/*"
|
||||||
|
|
||||||
|
get "/" do
|
||||||
|
"Hello World!"
|
||||||
|
end
|
||||||
|
|
||||||
|
Kemal.config.port = 3009
|
||||||
|
Kemal.run
|
Loading…
Reference in New Issue
Block a user