sinatra-cmd 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 176f2d20728d9dd8e5af6837185f937feaf136ee
|
4
|
+
data.tar.gz: 72af7c0f65ef1aa9aece11dbe9488bb97b96472e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61eca5a7e8e06f090ca806ffe796bef15c69afa3fbb6c32464d3e5d64630b532827b33a7cb126a190b019665c8ccac9b8a00fc6390bf5e74c3a1ae052ef99cce
|
7
|
+
data.tar.gz: 189a27aeab1b194a28b4a8d0a2676ae92cba3137b021018b6ed37ad07fdfa7ebd442ebe8c1cc23746fad129192f99728a7bbebd301910b014aebf944de1e31e7
|
@@ -35,6 +35,10 @@ module SinatraCmd
|
|
35
35
|
template "config/boot.rb.erb", "#{app_name}/config/boot.rb"
|
36
36
|
copy_file "config/environment.rb", "#{app_name}/config/environment.rb"
|
37
37
|
copy_file "config/scheduler.rb", "#{app_name}/config/scheduler.rb"
|
38
|
+
|
39
|
+
# i18n
|
40
|
+
copy_file "config/i18n/en-us.yml", "#{app_name}/config/i18n/en-us.yml"
|
41
|
+
copy_file "config/i18n/zh-cn.yml", "#{app_name}/config/i18n/zh-cn.yml"
|
38
42
|
end
|
39
43
|
|
40
44
|
def setup_appfile
|
data/lib/sinatra_cmd/version.rb
CHANGED
@@ -25,10 +25,12 @@ module <%= app_name.capitalize %>
|
|
25
25
|
headers("Content-Type" => "application/json; charset=UTF-8")
|
26
26
|
headers("Access-Control-Allow-Methods" => "POST, GET, PUT, DELETE, OPTION")
|
27
27
|
|
28
|
+
# fix Request header field Content-Type is not allowed by Access-Control-Allow-Headers.
|
29
|
+
# http://stackoverflow.com/questions/5027705/error-in-chrome-content-type-is-not-allowed-by-access-control-allow-headers
|
30
|
+
headers("Access-Control-Allow-Headers" => "Origin, X-Requested-With, Content-Type, Accept")
|
31
|
+
|
28
32
|
# For options
|
29
33
|
halt 200 if request.request_method == 'OPTIONS'
|
30
|
-
|
31
|
-
halt_with_401 unless %w(127.0.0.1 27.111.214.254 52.74.58.186).include?(request.ip)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -3,7 +3,10 @@ module <%= app_name.capitalize %>
|
|
3
3
|
def logger
|
4
4
|
return @logger unless @logger.nil?
|
5
5
|
|
6
|
-
|
6
|
+
file_path = File.join(File.expand_path('../../log', __FILE__))
|
7
|
+
FileUtils.mkdir_p(file_path)
|
8
|
+
|
9
|
+
@logger = Logger.new(File.join(file_path, "#{ENV['RACK_ENV']}.log"), 'daily')
|
7
10
|
@logger.level = Logger::INFO
|
8
11
|
@logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
9
12
|
@logger.formatter = proc {|severity, datetime, default_field , msg|
|
@@ -4,25 +4,27 @@ module <%= app_name.capitalize %>
|
|
4
4
|
def halt_with_400(message=nil)
|
5
5
|
message ||= t.error_handling.bad_request
|
6
6
|
logger.error("400, #{message}")
|
7
|
-
halt 400, json({code: 400,
|
7
|
+
halt 400, json({code: 400, error: message})
|
8
8
|
end
|
9
9
|
|
10
10
|
def halt_with_401(message=nil)
|
11
11
|
message ||= t.error_handling.authorization_required
|
12
|
+
# realm = "Example"
|
13
|
+
# headers 'WWW-Authenticate' => %(Basic realm="#{realm}")
|
12
14
|
logger.error("401, #{message}")
|
13
|
-
halt 401, json({code: 401,
|
15
|
+
halt 401, json({code: 401, error: message})
|
14
16
|
end
|
15
17
|
|
16
18
|
def halt_with_403(message=nil)
|
17
19
|
message ||= t.error_handling.forbidden
|
18
20
|
logger.error("403, #{message}")
|
19
|
-
halt 403, json({code: 403,
|
21
|
+
halt 403, json({code: 403, error: message})
|
20
22
|
end
|
21
23
|
|
22
24
|
def halt_with_404
|
23
25
|
message = t.error_handling.not_found
|
24
26
|
logger.error("404, #{message}")
|
25
|
-
halt 404, json({code: 404,
|
27
|
+
halt 404, json({code: 404, error: message})
|
26
28
|
end
|
27
29
|
|
28
30
|
# unprocessable_entity
|
@@ -42,13 +44,13 @@ module <%= app_name.capitalize %>
|
|
42
44
|
errors << {resource: resource, field: attribute, code: code}
|
43
45
|
end
|
44
46
|
logger.error("422, Validation failed")
|
45
|
-
halt 422, json({code: 422,
|
47
|
+
halt 422, json({code: 422, error: "Validation failed", errors: errors})
|
46
48
|
end
|
47
49
|
|
48
50
|
def halt_with_500
|
49
51
|
message = "#{t.error_handling.internal_server_error}: #{env['sinatra.error'].message}"
|
50
52
|
logger.error("500, #{message}")
|
51
|
-
halt 500, json({code: 500,
|
53
|
+
halt 500, json({code: 500, error: message})
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|