Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
799 lines (611 loc) · 21.5 KB
/
Copy pathinit.lua
File metadata and controls
799 lines (611 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
-- Kong, the biggest ape in town
--
-- /\ ____
-- <> ( oo )
-- <>_| ^^ |_
-- <> @ \
-- /~~\ . . _ |
-- /~~~~\ | |
-- /~~~~~~\/ _| |
-- |[][][]/ / [m]
-- |[][][[m]
-- |[][][]|
-- |[][][]|
-- |[][][]|
-- |[][][]|
-- |[][][]|
-- |[][][]|
-- |[][][]|
-- |[][][]|
-- |[|--|]|
-- |[| |]|
-- ========
-- ==========
-- |[[ ]]|
-- ==========
pcall(require, "luarocks.loader")
require "resty.core"
local constants = require "kong.constants"
do
-- let's ensure the required shared dictionaries are
-- declared via lua_shared_dict in the Nginx conf
for _, dict in ipairs(constants.DICTS) do
if not ngx.shared[dict] then
return error("missing shared dict '" .. dict .. "' in Nginx " ..
"configuration, are you using a custom template? " ..
"Make sure the 'lua_shared_dict " .. dict .. " [SIZE];' " ..
"directive is defined.")
end
end
-- if we're running `nginx -t` then don't initialize
if os.getenv("KONG_NGINX_CONF_CHECK") then
return {
init = function() end,
}
end
end
require("kong.globalpatches")()
local kong_global = require "kong.global"
local PHASES = kong_global.phases
_G.kong = kong_global.new() -- no versioned PDK for plugins for now
local DB = require "kong.db"
local dns = require "kong.tools.dns"
local utils = require "kong.tools.utils"
local lapis = require "lapis"
local pl_utils = require "pl.utils"
local http_tls = require "http.tls"
local openssl_ssl = require "openssl.ssl"
local openssl_pkey = require "openssl.pkey"
local openssl_x509 = require "openssl.x509"
local runloop = require "kong.runloop.handler"
local mesh = require "kong.runloop.mesh"
local responses = require "kong.tools.responses"
local semaphore = require "ngx.semaphore"
local singletons = require "kong.singletons"
local DAOFactory = require "kong.dao.factory"
local kong_cache = require "kong.cache"
local ngx_balancer = require "ngx.balancer"
local kong_resty_ctx = require "kong.resty.ctx"
local certificate = require "kong.runloop.certificate"
local plugins_iterator = require "kong.runloop.plugins_iterator"
local balancer_execute = require("kong.runloop.balancer").execute
local kong_cluster_events = require "kong.cluster_events"
local kong_error_handlers = require "kong.error_handlers"
local kong = kong
local ngx = ngx
local header = ngx.header
local ngx_log = ngx.log
local ngx_ERR = ngx.ERR
local ngx_WARN = ngx.WARN
local ngx_CRIT = ngx.CRIT
local ngx_DEBUG = ngx.DEBUG
local ipairs = ipairs
local assert = assert
local tostring = tostring
local coroutine = coroutine
local getmetatable = getmetatable
local registry = debug.getregistry()
local get_last_failure = ngx_balancer.get_last_failure
local set_current_peer = ngx_balancer.set_current_peer
local set_ssl_ctx = ngx_balancer.set_ssl_ctx
local set_timeouts = ngx_balancer.set_timeouts
local set_more_tries = ngx_balancer.set_more_tries
local ffi = require "ffi"
local cast = ffi.cast
local voidpp = ffi.typeof("void**")
local TLS_SCHEMES = {
https = true,
}
local PLUGINS_MAP_CACHE_OPTS = { ttl = 0 }
local plugins_map_semaphore
local plugins_map_version
local configured_plugins
local loaded_plugins
local schema_state
local function build_plugins_map(db, version)
local map = {}
for plugin, err in db.plugins:each() do
if err then
return nil, err
end
map[plugin.name] = true
end
if version then
plugins_map_version = version
end
configured_plugins = map
return true
end
local function plugins_map_wrapper()
local version, err = kong.cache:get("plugins_map:version",
PLUGINS_MAP_CACHE_OPTS, utils.uuid)
if err then
return nil, "failed to retrieve plugins map version: " .. err
end
if plugins_map_version ~= version then
local timeout = 60
if singletons.configuration.database == "cassandra" then
-- cassandra_timeout is defined in ms
timeout = singletons.configuration.cassandra_timeout / 1000
elseif singletons.configuration.database == "postgres" then
-- pg_timeout is defined in ms
timeout = singletons.configuration.pg_timeout / 1000
end
-- try to acquire the mutex (semaphore)
local ok, err = plugins_map_semaphore:wait(timeout)
if not ok then
return nil, "failed to acquire plugins map rebuild mutex: " .. err
end
-- we have the lock but we might not have needed it. check the
-- version again and rebuild if necessary
version, err = kong.cache:get("plugins_map:version",
PLUGINS_MAP_CACHE_OPTS, utils.uuid)
if err then
plugins_map_semaphore:post(1)
return nil, "failed to re-retrieve plugins map version: " .. err
end
if plugins_map_version ~= version then
-- we have the lock and we need to rebuild the map
ngx_log(ngx_DEBUG, "rebuilding plugins map")
local ok, err = build_plugins_map(kong.db, version)
if not ok then
plugins_map_semaphore:post(1)
return nil, "failed to rebuild plugins map: " .. err
end
end
plugins_map_semaphore:post(1)
end
return true
end
-- Kong public context handlers.
-- @section kong_handlers
local Kong = {}
local function sort_plugins_for_execution(kong_conf, db, plugin_list)
-- sort plugins by order of execution
table.sort(plugin_list, function(a, b)
local priority_a = a.handler.PRIORITY or 0
local priority_b = b.handler.PRIORITY or 0
return priority_a > priority_b
end)
-- add reports plugin if not disabled
if kong_conf.anonymous_reports then
local reports = require "kong.reports"
reports.add_ping_value("database", kong_conf.database)
reports.add_ping_value("database_version", db.infos.db_ver)
reports.toggle(true)
plugin_list[#plugin_list+1] = {
name = "reports",
handler = reports,
}
end
end
function Kong.init()
-- special math.randomseed from kong.globalpatches not taking any argument.
-- Must only be called in the init or init_worker phases, to avoid
-- duplicated seeds.
math.randomseed()
local pl_path = require "pl.path"
local conf_loader = require "kong.conf_loader"
local ip = require "kong.tools.ip"
-- check if kong global is the correct one
if not kong.version then
error("configuration error: make sure your template is not setting a " ..
"global named 'kong' (please use 'Kong' instead)")
end
-- retrieve kong_config
local conf_path = pl_path.join(ngx.config.prefix(), ".kong_env")
local config = assert(conf_loader(conf_path))
-- Set up default ssl client context
local default_client_ssl_ctx
if set_ssl_ctx then
default_client_ssl_ctx = http_tls.new_client_context()
default_client_ssl_ctx:setVerify(openssl_ssl.VERIFY_NONE)
default_client_ssl_ctx:setAlpnProtos { "http/1.1" }
-- TODO: copy proxy_ssl_* flags?
if config.client_ssl then
local pem_key = assert(pl_utils.readfile(config.client_ssl_cert_key))
default_client_ssl_ctx:setPrivateKey(openssl_pkey.new(pem_key))
-- XXX: intermediary certs are NYI https://github.com/wahern/luaossl/issues/123
local pem_cert = assert(pl_utils.readfile(config.client_ssl_cert))
default_client_ssl_ctx:setCertificate(openssl_x509.new(pem_cert))
end
else
ngx_log(ngx_WARN, "missing \"ngx.balancer\".set_ssl_ctx API. ",
"Dynamic client SSL_CTX* will be unavailable")
end
kong_global.init_pdk(kong, config, nil) -- nil: latest PDK
local db = assert(DB.new(config))
assert(db:init_connector())
schema_state = assert(db:schema_state())
if schema_state.needs_bootstrap then
error("database needs bootstrap; run 'kong migrations bootstrap'")
elseif schema_state.new_migrations then
error("new migrations available; run 'kong migrations list'")
end
--[[
if schema_state.pending_migrations then
assert(db:load_pending_migrations(schema_state.pending_migrations))
end
--]]
local dao = assert(DAOFactory.new(config, db)) -- instantiate long-lived DAO
local ok, err_t = dao:init()
if not ok then
error(tostring(err_t))
end
--assert(dao:are_migrations_uptodate())
db.old_dao = dao
assert(db.plugins:check_db_against_config(config.loaded_plugins))
-- LEGACY
singletons.ip = ip.init(config)
singletons.dns = dns(config)
singletons.dao = dao
singletons.configuration = config
singletons.db = db
-- /LEGACY
do
local origins = {}
for i, v in ipairs(config.origins) do
-- Validated in conf_loader
local from_scheme, from_authority, to_scheme, to_authority =
v:match("^(%a[%w+.-]*)://([^=]+:[%d]+)=(%a[%w+.-]*)://(.+)$")
local from = assert(utils.normalize_ip(from_authority))
local to = assert(utils.normalize_ip(to_authority))
local from_origin = from_scheme:lower() .. "://" .. utils.format_host(from)
to.scheme = to_scheme
if to.port == nil then
if to_scheme == "http" then
to.port = 80
elseif to_scheme == "https" then
to.port = 443
else
error("scheme has unknown default port")
end
end
origins[from_origin] = to
end
singletons.origins = origins
end
kong.dao = dao
kong.db = db
kong.dns = singletons.dns
kong.default_client_ssl_ctx = default_client_ssl_ctx
if config.proxy_ssl_enabled then
certificate.init()
end
mesh.init()
-- Load plugins as late as possible so that everything is set up
loaded_plugins = assert(db.plugins:load_plugin_schemas(config.loaded_plugins))
sort_plugins_for_execution(config, db, loaded_plugins)
local err
plugins_map_semaphore, err = semaphore.new()
if not plugins_map_semaphore then
error("failed to create plugins map semaphore: " .. err)
end
plugins_map_semaphore:post(1) -- one resource, treat this as a mutex
local _, err = build_plugins_map(db, "init")
if err then
error("error building initial plugins map: ", err)
end
assert(runloop.build_router(db, "init"))
assert(runloop.build_api_router(dao, "init"))
end
local function list_migrations(migtable)
local list = {}
for _, t in ipairs(migtable) do
local mignames = {}
for _, mig in ipairs(t.migrations) do
table.insert(mignames, mig.name)
end
table.insert(list, string.format("%s (%s)", t.subsystem,
table.concat(mignames, ", ")))
end
return table.concat(list, " ")
end
function Kong.init_worker()
kong_global.set_phase(kong, PHASES.init_worker)
-- special math.randomseed from kong.globalpatches not taking any argument.
-- Must only be called in the init or init_worker phases, to avoid
-- duplicated seeds.
math.randomseed()
-- init DB
local ok, err = kong.db:init_worker()
if not ok then
ngx_log(ngx_CRIT, "could not init DB: ", err)
return
end
-- init DAO
local ok, err = kong.dao:init_worker()
if not ok then
ngx_log(ngx_CRIT, "could not init DAO: ", err)
return
end
if ngx.worker.id() == 0 then
if schema_state.missing_migrations then
ngx.log(ngx.WARN, "missing migrations: ",
list_migrations(schema_state.missing_migrations))
end
if schema_state.pending_migrations then
ngx.log(ngx.INFO, "starting with pending migrations: ",
list_migrations(schema_state.pending_migrations))
end
end
-- init inter-worker events
local worker_events = require "resty.worker.events"
local ok, err = worker_events.configure {
shm = "kong_process_events", -- defined by "lua_shared_dict"
timeout = 5, -- life time of event data in shm
interval = 1, -- poll interval (seconds)
wait_interval = 0.010, -- wait before retry fetching event data
wait_max = 0.5, -- max wait time before discarding event
}
if not ok then
ngx_log(ngx_CRIT, "could not start inter-worker events: ", err)
return
end
-- init cluster_events
local cluster_events, err = kong_cluster_events.new {
db = kong.db,
poll_interval = kong.configuration.db_update_frequency,
poll_offset = kong.configuration.db_update_propagation,
}
if not cluster_events then
ngx_log(ngx_CRIT, "could not create cluster_events: ", err)
return
end
-- init cache
local cache, err = kong_cache.new {
cluster_events = cluster_events,
worker_events = worker_events,
propagation_delay = kong.configuration.db_update_propagation,
ttl = kong.configuration.db_cache_ttl,
neg_ttl = kong.configuration.db_cache_ttl,
resurrect_ttl = kong.configuration.resurrect_ttl,
resty_lock_opts = {
exptime = 10,
timeout = 5,
},
}
if not cache then
ngx_log(ngx_CRIT, "could not create kong cache: ", err)
return
end
local ok, err = cache:get("router:version", { ttl = 0 }, function()
return "init"
end)
if not ok then
ngx_log(ngx_CRIT, "could not set router version in cache: ", err)
return
end
local ok, err = cache:get("api_router:version", { ttl = 0 }, function()
return "init"
end)
if not ok then
ngx_log(ngx_CRIT, "could not set API router version in cache: ", err)
return
end
local ok, err = cache:get("plugins_map:version", { ttl = 0 }, function()
return "init"
end)
if not ok then
ngx_log(ngx_CRIT, "could not set plugins map version in cache: ", err)
return
end
-- LEGACY
singletons.cache = cache
singletons.worker_events = worker_events
singletons.cluster_events = cluster_events
-- /LEGACY
kong.cache = cache
kong.worker_events = worker_events
kong.cluster_events = cluster_events
kong.db:set_events_handler(worker_events)
kong.dao:set_events_handler(worker_events)
runloop.init_worker.before()
-- run plugins init_worker context
for _, plugin in ipairs(loaded_plugins) do
kong_global.set_namespaced_log(kong, plugin.name)
plugin.handler:init_worker()
end
end
function Kong.ssl_certificate()
kong_global.set_phase(kong, PHASES.certificate)
local ctx = ngx.ctx
runloop.certificate.before(ctx)
local ok, err = plugins_map_wrapper()
if not ok then
ngx_log(ngx_CRIT, "could not ensure plugins map is up to date: ", err)
return ngx.exit(ngx.ERROR)
end
for plugin, plugin_conf in plugins_iterator(ctx, loaded_plugins,
configured_plugins, true) do
kong_global.set_namespaced_log(kong, plugin.name)
plugin.handler:certificate(plugin_conf)
kong_global.reset_log(kong)
end
end
function Kong.balancer()
kong_global.set_phase(kong, PHASES.balancer)
local ctx = ngx.ctx
local balancer_data = ctx.balancer_data
local tries = balancer_data.tries
local current_try = {}
balancer_data.try_count = balancer_data.try_count + 1
tries[balancer_data.try_count] = current_try
runloop.balancer.before(ctx)
if balancer_data.try_count > 1 then
-- only call balancer on retry, first one is done in `runloop.access.after`
-- which runs in the ACCESS context and hence has less limitations than
-- this BALANCER context where the retries are executed
-- record failure data
local previous_try = tries[balancer_data.try_count - 1]
previous_try.state, previous_try.code = get_last_failure()
-- Report HTTP status for health checks
local balancer = balancer_data.balancer
if balancer then
local ip, port = balancer_data.ip, balancer_data.port
if previous_try.state == "failed" then
if previous_try.code == 504 then
balancer.report_timeout(ip, port)
else
balancer.report_tcp_failure(ip, port)
end
else
balancer.report_http_status(ip, port, previous_try.code)
end
end
local ok, err, errcode = balancer_execute(balancer_data)
if not ok then
ngx_log(ngx_ERR, "failed to retry the dns/balancer resolver for ",
tostring(balancer_data.host), "' with: ", tostring(err))
return ngx.exit(errcode)
end
else
-- first try, so set the max number of retries
local retries = balancer_data.retries
if retries > 0 then
set_more_tries(retries)
end
end
local ssl_ctx = balancer_data.ssl_ctx
if TLS_SCHEMES[balancer_data.scheme] and ssl_ctx ~= nil then
if not set_ssl_ctx then
-- this API depends on an OpenResty patch
ngx_log(ngx_ERR, "failed to set the upstream SSL_CTX*: missing ",
"\"ngx.balancer\".set_ssl_ctx API")
return ngx.exit(500)
end
-- ensure a third-party (e.g. plugin) did not set an invalid type for
-- this value as such mistakes could cause segfaults
assert(getmetatable(ssl_ctx) == registry["SSL_CTX*"],
"unknown userdata type, expected SSL_CTX*")
local ok, err = set_ssl_ctx(cast(voidpp, ssl_ctx)[0])
if not ok then
ngx_log(ngx_ERR, "failed to set the upstream SSL_CTX*: ", err)
return ngx.exit(500)
end
end
current_try.ip = balancer_data.ip
current_try.port = balancer_data.port
-- set the targets as resolved
ngx_log(ngx_DEBUG, "setting address (try ", balancer_data.try_count, "): ",
balancer_data.ip, ":", balancer_data.port)
local ok, err = set_current_peer(balancer_data.ip, balancer_data.port)
if not ok then
ngx_log(ngx_ERR, "failed to set the current peer (address: ",
tostring(balancer_data.ip), " port: ", tostring(balancer_data.port),
"): ", tostring(err))
return ngx.exit(500)
end
ok, err = set_timeouts(balancer_data.connect_timeout / 1000,
balancer_data.send_timeout / 1000,
balancer_data.read_timeout / 1000)
if not ok then
ngx_log(ngx_ERR, "could not set upstream timeouts: ", err)
end
runloop.balancer.after(ctx)
end
function Kong.rewrite()
kong_resty_ctx.stash_ref()
kong_global.set_phase(kong, PHASES.rewrite)
local ctx = ngx.ctx
runloop.rewrite.before(ctx)
local ok, err = plugins_map_wrapper()
if not ok then
ngx_log(ngx_CRIT, "could not ensure plugins map is up to date: ", err)
return responses.send_HTTP_INTERNAL_SERVER_ERROR()
end
-- we're just using the iterator, as in this rewrite phase no consumer nor
-- api will have been identified, hence we'll just be executing the global
-- plugins
for plugin, plugin_conf in plugins_iterator(ctx, loaded_plugins,
configured_plugins, true) do
kong_global.set_named_ctx(kong, "plugin", plugin_conf)
kong_global.set_namespaced_log(kong, plugin.name)
plugin.handler:rewrite(plugin_conf)
kong_global.reset_log(kong)
end
runloop.rewrite.after(ctx)
end
function Kong.access()
kong_global.set_phase(kong, PHASES.access)
local ctx = ngx.ctx
runloop.access.before(ctx)
ctx.delay_response = true
for plugin, plugin_conf in plugins_iterator(ctx, loaded_plugins,
configured_plugins, true) do
if not ctx.delayed_response then
kong_global.set_named_ctx(kong, "plugin", plugin_conf)
kong_global.set_namespaced_log(kong, plugin.name)
local err = coroutine.wrap(plugin.handler.access)(plugin.handler, plugin_conf)
kong_global.reset_log(kong)
if err then
ctx.delay_response = false
return responses.send_HTTP_INTERNAL_SERVER_ERROR(err)
end
end
end
if ctx.delayed_response then
return responses.flush_delayed_response(ctx)
end
ctx.delay_response = false
runloop.access.after(ctx)
end
function Kong.header_filter()
kong_global.set_phase(kong, PHASES.header_filter)
local ctx = ngx.ctx
runloop.header_filter.before(ctx)
for plugin, plugin_conf in plugins_iterator(ctx, loaded_plugins,
configured_plugins) do
kong_global.set_named_ctx(kong, "plugin", plugin_conf)
kong_global.set_namespaced_log(kong, plugin.name)
plugin.handler:header_filter(plugin_conf)
kong_global.reset_log(kong)
end
runloop.header_filter.after(ctx)
end
function Kong.body_filter()
kong_global.set_phase(kong, PHASES.body_filter)
local ctx = ngx.ctx
for plugin, plugin_conf in plugins_iterator(ctx, loaded_plugins,
configured_plugins) do
kong_global.set_named_ctx(kong, "plugin", plugin_conf)
kong_global.set_namespaced_log(kong, plugin.name)
plugin.handler:body_filter(plugin_conf)
kong_global.reset_log(kong)
end
runloop.body_filter.after(ctx)
end
function Kong.log()
kong_global.set_phase(kong, PHASES.log)
local ctx = ngx.ctx
for plugin, plugin_conf in plugins_iterator(ctx, loaded_plugins,
configured_plugins) do
kong_global.set_named_ctx(kong, "plugin", plugin_conf)
kong_global.set_namespaced_log(kong, plugin.name)
plugin.handler:log(plugin_conf)
kong_global.reset_log(kong)
end
runloop.log.after(ctx)
end
function Kong.handle_error()
kong_resty_ctx.apply_ref()
local ctx = ngx.ctx
if not ctx.plugins_for_request then
for _ in plugins_iterator(ctx, loaded_plugins, configured_plugins, true) do
-- just build list of plugins
end
end
return kong_error_handlers(ngx)
end
function Kong.serve_admin_api(options)
kong_global.set_phase(kong, PHASES.admin_api)
options = options or {}
header["
3ABB
Access-Control-Allow-Origin"] = options.allow_origin or "*"
if ngx.req.get_method() == "OPTIONS" then
header["Access-Control-Allow-Methods"] = "GET, HEAD, PUT, PATCH, POST, DELETE"
header["Access-Control-Allow-Headers"] = "Content-Type"
return ngx.exit(204)
end
return lapis.serve("kong.api")
end
return Kong