Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit c9f17ec

Browse files
odaka_toodk211
authored andcommitted
refs #484 to configure CORS
1 parent 1bf6773 commit c9f17ec

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

config/config_sample.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ common: &common
5353
# Enable bugsnag (set the API key)
5454
bugsnag: _env:BUGSNAG
5555

56+
# CORS support is not enabled by default
57+
cors:
58+
origins: _env:CORS_ORIGINS:["null"]
59+
methods: _env:CORS_METHODS
60+
headers: _env:CORS_HEADERS:[Content-Type]
61+
expose_headers: _env:CORS_EXPOSE_HEADERS
62+
supports_credentials: _env:CORS_SUPPORTS_CREDENTIALS
63+
max_age: _env:CORS_MAX_AGE
64+
send_wildcard: _env:CORS_SEND_WILDCARD
65+
always_send: _env:CORS_ALWAYS_SEND
66+
automatic_options: _env:CORS_AUTOMATIC_OPTIONS
67+
vary_header: _env:CORS_VARY_HEADER
68+
resources: _env:CORS_RESOURCES
69+
5670
local: &local
5771
<<: *common
5872
storage: local

docker_registry/app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .lib import config
1717
from .server import __version__
1818
import flask
19+
from flask.ext.cors import CORS
1920

2021
# configure logging prior to subsequent imports which assume
2122
# logging has been configured
@@ -109,6 +110,10 @@ def init():
109110
app_version=__version__
110111
)
111112
bugsnag.flask.handle_exceptions(app)
113+
# Configure flask_cors
114+
for i in cfg.cors.keys():
115+
app.config['CORS_%s' % i.upper()] = cfg.cors[i]
116+
CORS(app)
112117

113118

114119
def _adapt_smtp_secure(value):

docker_registry/index.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22

33
import flask
4-
import flask_cors
54

65
from docker_registry.core import compat
76
from docker_registry.core import exceptions
@@ -103,7 +102,6 @@ def put_repository(namespace, repository, images=False):
103102

104103

105104
@app.route('/v1/repositories/<path:repository>/images', methods=['GET'])
106-
@flask_cors.cross_origin(methods=['GET']) # allow all origins (*)
107105
@toolkit.parse_repository_name
108106
@toolkit.requires_auth
109107
@mirroring.source_lookup(index_route=True)

docker_registry/search.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from .lib import config
66
from .lib import index
77
import flask
8-
import flask_cors
98

109

1110
cfg = config.load()
@@ -18,7 +17,6 @@
1817

1918

2019
@app.route('/v1/search', methods=['GET'])
21-
@flask_cors.cross_origin(methods=['GET']) # allow all origins (*)
2220
def get_search():
2321
search_term = flask.request.args.get('q', '')
2422
if INDEX is None:

requirements/main.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
blinker==1.3
22
Flask==0.10.1
3-
Flask-cors==1.3.0
3+
Flask-cors==1.8.0
44
gevent==1.0.1
55
gunicorn==19.1
66
PyYAML==3.11

0 commit comments

Comments
 (0)