Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default index file for static directory #512

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions samcli/local/apigw/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def create(self):
static_folder=self.static_dir # Serve static files from this directory
)

self._app.add_url_rule('/', 'index', self.index)

for api_gateway_route in self.routing_list:
path = PathConverter.convert_path_to_flask(api_gateway_route.path)
for route_key in self._generate_route_keys(api_gateway_route.methods,
Expand Down Expand Up @@ -445,3 +447,14 @@ def _should_base64_encode(binary_types, request_mimetype):

"""
return request_mimetype in binary_types or "*/*" in binary_types

def index(self):
"""
Default Index file

Returns
-------
index.html

"""
return self._app.send_static_file('index.html')
12 changes: 7 additions & 5 deletions tests/unit/local/apigw/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ def test_create_creates_flask_app_with_url_rules(self, flask):

self.service.create()

app_mock.add_url_rule.assert_called_once_with('/',
endpoint='/',
view_func=self.service._request_handler,
methods=['GET'],
provide_automatic_options=False)
app_mock.add_url_rule.assert_any_call('/', 'index', self.service.index)

app_mock.add_url_rule.assert_any_call('/',
endpoint='/',
view_func=self.service._request_handler,
methods=['GET'],
provide_automatic_options=False)

def test_initalize_creates_default_values(self):
self.assertEquals(self.service.port, 3000)
Expand Down