Use baked file system for public folder #102
|
@ -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
|
||||
|
|
|
@ -69,3 +69,5 @@ dependencies:
|
|||
github: ysbaddaden/pool
|
||||
athena:
|
||||
github: athena-framework/framework
|
||||
baked_file_system:
|
||||
github: schovi/baked_file_system
|
||||
|
|
9
docker/backend/src/backend/public.cr
Normal file
9
docker/backend/src/backend/public.cr
Normal file
|
@ -0,0 +1,9 @@
|
|||
require "baked_file_system"
|
||||
|
||||
module Backend
|
||||
module Public
|
||||
extend BakedFileSystem
|
||||
|
||||
bake_folder "../../public"
|
||||
end
|
||||
end
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue