[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [donate/master] Added header response to allow request from the Lektor donate pages.



commit 058a34929446f4ee337755677ca5ec50e5ccea29
Author: skirtiadi <skirtiadi@xxxxxxxxxxxxxxx>
Date:   Fri Jun 19 15:51:10 2020 -0700

    Added header response to allow request from the Lektor donate pages.
    
    Added a section in README to add the Tor lektor site base url.
    
    Issue #45530
---
 README.md                       |  9 +++++++++
 src/AccessControlMiddleware.php | 18 ++++++++++++++++++
 src/middleware.php              |  1 +
 src/routes.php                  |  4 ++++
 src/settings.php                |  6 ++++++
 5 files changed, 38 insertions(+)

diff --git a/README.md b/README.md
index bdb50ac6..f3502637 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,15 @@ $stripeSettings['secretKey'] = 'Input-SecretKey-here(Sylvanus)';
 $stripeSettings['publishableKey'] = 'Input-PublishableKey-here(Sylvanus)';
 ```
 
+For local developments only, create a file at private/settings.local.php.
+It should have this in it:
+
+``` php
+<?php
+
+$torSiteBaseUrl = 'http://localhost:5000';
+```
+
 You'll need to setup your Apache config to point to the public subdirectory in the repository.
 
 Now to do development, just run:
diff --git a/src/AccessControlMiddleware.php b/src/AccessControlMiddleware.php
new file mode 100644
index 00000000..d900fa63
--- /dev/null
+++ b/src/AccessControlMiddleware.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Tor;
+
+class AccessControlMiddleware {
+  public function __invoke($request, $response, $next) {
+    $response = $response->withHeader('Access-Control-Allow-Origin', $this->torSiteBaseUrl);
+    $response = $response->withHeader('Access-Control-Allow-Credentials', 'true');
+    $response = $response->withHeader('Access-Control-Allow-Headers', 'Content-Type');
+    return $next($request, $response);
+  }
+
+  function __construct($app) {
+    $this->app = $app;
+    $this->container = $app->getContainer();
+    $this->torSiteBaseUrl = $this->container->get('settings')['torSiteBaseUrl'];
+  }
+}
diff --git a/src/middleware.php b/src/middleware.php
index a2c120df..dbd629f1 100644
--- a/src/middleware.php
+++ b/src/middleware.php
@@ -3,4 +3,5 @@
 
 // e.g: $app->add(new \Slim\Csrf\Guard);
 $app->add(new \Tor\I18nMiddleware($app));
+$app->add(new \Tor\AccessControlMiddleware($app));
 $app->add(new  RKA\Middleware\IpAddress());
diff --git a/src/routes.php b/src/routes.php
index cf75ef92..3c4d63c0 100644
--- a/src/routes.php
+++ b/src/routes.php
@@ -133,3 +133,7 @@ $app->get('/captcha', function($request, $response, $args) {
   $controller = new \Tor\Captcha($this);
   return $controller->generate($request, $response, $args);
 });
+
+$app->options('/{routes:.+}', function ($request, $response, $args) {
+    return $response;
+});
diff --git a/src/settings.php b/src/settings.php
index bb6ba7a2..0324bbae 100644
--- a/src/settings.php
+++ b/src/settings.php
@@ -1,6 +1,11 @@
 <?php
 
 define('PP_CONFIG_PATH', __DIR__ . '/../private');
+require PP_CONFIG_PATH . '/settings.local.php';
+
+if (!isset($torSiteBaseUrl)) {
+  $torSiteBaseUrl = 'https://www.torproject.org/';
+}
 
 $config = [
   'settings' => [
@@ -50,6 +55,7 @@ $config = [
       'sandbox' => 'AZc7yGlGGXnOjwt55x4wRGbWHo7Fdj83JAu0lqYruVWVoYa7JfQhy5F_ucy2mR6CjPmpmJwmtHONjTeB',
       'production' => 'AbzwWJgUgwGMvTupfvigx1yAj75jNnCj4mFGC_VbiROUi2TfVwPS9IZ5MfqLsSUnXJFSMwaSaTR4FY_A'
     ],
+    'torSiteBaseUrl' => $torSiteBaseUrl,
   ],
 ];
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits