Merge pull request 'Use baked file system for public folder' (#102) from baked-file-system-for-public-folder into main
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: mentorenwahl/mentorenwahl#102
This commit is contained in:
Dominic Grimm 2022-03-20 19:50:57 +00:00
commit 80df5d6b32
4 changed files with 23 additions and 4 deletions

View file

@ -32,6 +32,10 @@ shards:
git: https://github.com/athena-framework/validator.git
version: 0.1.7
baked_file_system:
git: https://github.com/schovi/baked_file_system.git
version: 0.10.0
bindata:
git: https://github.com/spider-gazelle/bindata.git
version: 1.10.0

View file

@ -69,3 +69,5 @@ dependencies:
github: ysbaddaden/pool
athena:
github: athena-framework/framework
baked_file_system:
github: schovi/baked_file_system

View file

@ -0,0 +1,9 @@
require "baked_file_system"
module Backend
module Public
extend BakedFileSystem
bake_folder "../../public"
end
end

View file

@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
require "mime"
require "http/headers"
module Backend
module Web
@ -25,10 +25,14 @@ module Backend
@[ARTA::Get("")]
def playground : ATH::Response | ATH::Exceptions::HTTPException
{% if flag?(:development) %}
render "public/index.html"
ATH::StreamedResponse.new(headers: HTTP::Headers{"content-type" => "text/html"}) do |io|
IO.copy(Public.get("index.html"), io)
end
{% else %}
if Backend.config.api.graphql_playground_fully_enabled?
render "public/index.html"
ATH::StreamedResponse.new(headers: HTTP::Headers{"content-type" => "text/html"}) do |io|
IO.copy(Public.get("index.html"), io)
end
else
ATH::Exceptions::ServiceUnavailable.new("GraphQL Playground is not enabled. Please enable it in the backend configuration.")
end
@ -43,7 +47,7 @@ module Backend
Log.notice { "Development request icoming" } if development
{% end %}
ATH::StreamedResponse.new(headers: HTTP::Headers{"content-type" => MIME.from_extension(".json")}) do |io|
ATH::StreamedResponse.new(headers: HTTP::Headers{"content-type" => "application/json"}) do |io|
Api::Schema::SCHEMA.execute(
io,
query.query,