浏览代码

Support JSON rendering for API

v1
Aeris 5 年前
父节点
当前提交
51f478125a
共有 1 个文件被更改,包括 19 次插入2 次删除
  1. +19
    -2
      app/controllers/check_controller.rb

+ 19
- 2
app/controllers/check_controller.rb 查看文件

@@ -5,8 +5,19 @@ class CheckController < ApplicationController
def show
enqueue_host unless @result
@host = SimpleIDN.to_unicode @host
return render :processing if @result.pending
return render :no_tls if @result.no_tls
respond_to do |format|
format.html do
return render :processing if @result.pending
return render :no_tls if @result.no_tls
end
format.json do
render json: case
when @result.pending then :pending
when @result.no_tls then :no_tls
else @result
end
end
end
end

def refresh
@@ -30,6 +41,12 @@ class CheckController < ApplicationController

def check_host
@id = params[:id]

if @id.end_with? '.json'
@id = @id.sub /\.json$/, ''
request.format = :json
end

@host, @port = @id.split ':'
@host = SimpleIDN.to_ascii @host.downcase
if /[^a-zA-Z0-9.-]/.match @host


正在加载...
取消
保存