Skip to content

Commit

Permalink
Redirect based on file extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Jan 27, 2022
1 parent ec6ad68 commit cd80bda
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions voila/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import asyncio
import os
from typing import Dict
from pathlib import Path

import tornado.web
from jupyter_server.base.handlers import JupyterHandler
Expand Down Expand Up @@ -116,6 +117,18 @@ async def get_generator(self, path=None):

else:
# All kernels are used or pre-heated kernel is disabled, start a normal kernel.
supported_file_extensions = ['.ipynb']
supported_file_extensions.extend(
[
x.lower()
for x in self.voila_configuration.extension_language_mapping.keys()
]
)
file_extenstion = Path(notebook_path).suffix.lower()
if file_extenstion not in supported_file_extensions:
self.redirect_to_file(path)
return

gen = NotebookRenderer(
voila_configuration=self.voila_configuration,
traitlet_config=self.traitlet_config,
Expand All @@ -129,8 +142,7 @@ async def get_generator(self, path=None):

done = await gen.initialize(template=template_arg, theme=theme_arg)
if not done:
self.redirect_to_file(path)
return
raise tornado.web.HTTPError(404, 'NotebookRenderer has failed to initialize!')

def time_out():
"""If not done within the timeout, we send a heartbeat
Expand Down

0 comments on commit cd80bda

Please sign in to comment.