From f1080362b2cb875f7085050eee9b720df2c910c3 Mon Sep 17 00:00:00 2001 From: Hans Nieser Date: Fri, 2 Jun 2023 09:24:12 +0200 Subject: [PATCH] Initial commit --- composer.json | 24 ++++++++++++++ registration.php | 9 ++++++ src/Controller/Index/Index.php | 58 ++++++++++++++++++++++++++++++++++ src/etc/csp_whitelist.xml | 16 ++++++++++ src/etc/frontend/routes.xml | 8 +++++ src/etc/module.xml | 8 +++++ 6 files changed, 123 insertions(+) create mode 100644 composer.json create mode 100644 registration.php create mode 100644 src/Controller/Index/Index.php create mode 100644 src/etc/csp_whitelist.xml create mode 100644 src/etc/frontend/routes.xml create mode 100644 src/etc/module.xml diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..bc0b8e5 --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "reach-digital/magento2-apollo-sandbox", + "description": "Embeds Apollo Sandbox at /graphql-sandbox", + "authors": [ + { + "name": "Hans Nieser", + "email": "hans@reachdigital.nl" + } + ], + "require": { + "php": "~7.4.0||~8.1.0", + "magento/product-community-edition": "^2.3" + }, + "type": "magento2-module", + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "ReachDigital\\ApolloSandbox\\": "src/" + } + } +} + diff --git a/registration.php b/registration.php new file mode 100644 index 0000000..bafa072 --- /dev/null +++ b/registration.php @@ -0,0 +1,9 @@ +rawFactory = $rawFactory; + $this->urlBuilder = $urlBuilder; + $this->escaper = $escaper; + } + + /** + * @inheritDoc + */ + public function execute() + { + $rawResponse = $this->rawFactory->create(); + $rawResponse->setContents($this->getEmbedScript()); + return $rawResponse; + } + + private function getEmbedScript(): string + { + return ' +
+ + + '; + } + + private function getGraphqlUrl(): string + { + return rtrim($this->urlBuilder->getBaseUrl(), '/') . '/graphql'; + } +} diff --git a/src/etc/csp_whitelist.xml b/src/etc/csp_whitelist.xml new file mode 100644 index 0000000..ecf00fa --- /dev/null +++ b/src/etc/csp_whitelist.xml @@ -0,0 +1,16 @@ + + + + + + embeddable-sandbox.cdn.apollographql.com + + + + + sandbox.embed.apollographql.com/ + + + + diff --git a/src/etc/frontend/routes.xml b/src/etc/frontend/routes.xml new file mode 100644 index 0000000..c960e77 --- /dev/null +++ b/src/etc/frontend/routes.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/etc/module.xml b/src/etc/module.xml new file mode 100644 index 0000000..8fbf189 --- /dev/null +++ b/src/etc/module.xml @@ -0,0 +1,8 @@ + + + + + + + +