Heroku using nginx, reverted public and some fixes

This commit is contained in:
Pablo Ferreiro 2022-03-13 18:22:36 +01:00
parent 8ece2c2b25
commit 1b29950d89
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
15 changed files with 38 additions and 33 deletions

View file

@ -5,3 +5,8 @@ RewriteRule ^ index.php [QSA,L]
# Disable index view # Disable index view
Options -Indexes Options -Indexes
<Files .env>
Order allow,deny
Deny from all
</Files>

View file

@ -1 +1 @@
web: vendor/bin/heroku-php-apache2 public/ web: vendor/bin/heroku-php-nginx -C ./setup/nginx.conf

View file

@ -31,16 +31,14 @@ Clone the repository and fetch the requiered external packages with:
```bash ```bash
composer install composer install
``` ```
Move the .env.example file to .env and modify it.
Then you can run it using for example the PHP Development Server with: Then you can run it using for example the PHP Development Server with:
```bash ```bash
php -S localhost:8080 -t public php -S localhost:8080
``` ```
## Configuration ## Configuration
### .env
Move the .env.example file to .env and modify it.
### Cache engines ### Cache engines
Available cache engines: Available cache engines:
* redis: Writes response to Redis * redis: Writes response to Redis
@ -50,21 +48,7 @@ Available cache engines:
You don't have to do anything more You don't have to do anything more
### Nginx ### Nginx
Add the following to your config (you can modify the proxitok part if you have or not a subdir): You can get a config example on /setup/nginx.conf
```
location /proxitok {
return 302 $scheme://$host/proxitok/;
}
location /proxitok/ {
try_files $uri $uri/ /proxitok/index.php?$query_string;
}
location /proxitok/.env {
deny all;
return 404;
}
```
## TODO ## TODO
* Add a NoJS version / Make the whole program without required JS * Add a NoJS version / Make the whole program without required JS

View file

@ -11,19 +11,26 @@ class SettingsController {
$latte->render(Misc::getView('settings'), new SettingsTemplate); $latte->render(Misc::getView('settings'), new SettingsTemplate);
} }
static private function redirect() {
$url = Misc::url('/settings');
header("Location: {$url}");
}
static public function proxy() { static public function proxy() {
if (in_array(Cookies::PROXY, $_POST)) { if (in_array(Cookies::PROXY, $_POST)) {
foreach (Cookies::PROXY as $proxy_element) { foreach (Cookies::PROXY as $proxy_element) {
Cookies::set($proxy_element, $_POST[$proxy_element]); Cookies::set($proxy_element, $_POST[$proxy_element]);
} }
} }
$url = Misc::url('/settings'); self::redirect();
header("Location: {$url}");
} }
static public function api() { static public function api() {
$_POST['legacy'] ?? Cookies::set('api-legacy', '1'); $legacy = 'off';
$url = Misc::url('/settings'); if (isset($_POST['api-legacy'])) {
header("Location: {$url}"); $legacy = 'on';
}
Cookies::set('api-legacy', $legacy);
self::redirect();
} }
} }

View file

@ -78,8 +78,7 @@ class Misc {
} }
// Legacy mode // Legacy mode
$_COOKIE['enable_legacy'] ?? $legacy = true; // User level $legacy = self::env('FORCE_LEGACY', false) || isset($_COOKIE['api-legacy']) && $_COOKIE['api-legacy'] === 'on';
$legacy = self::env('FORCE_LEGACY', false); // Instance level (has priority over user)
return $legacy === false ? new \TikScraper\Api($options, $cacheEngine) : new \TikScraper\Legacy($options, $cacheEngine); return $legacy === false ? new \TikScraper\Api($options, $cacheEngine) : new \TikScraper\Legacy($options, $cacheEngine);
} }

View file

@ -1,7 +1,9 @@
<form action="{path('/settings/api')}" method="POST"> <form action="{path('/settings/api')}" method="POST">
<div class="field"> <div class="field">
<label class="checkbox"> <label class="checkbox">
<input name="api-legacy" type="checkbox" checked="{isset($_COOKIE['api-legacy']) ? 'true' : 'false'}">Enable legacy mode <input name="api-legacy" type="checkbox"
checked="{isset($_COOKIE['api-legacy']) && $_COOKIE['api-legacy'] === 'on' ? 'true' : 'false'}"
value="{isset($_COOKIE['api-legacy']) ? $_COOKIE['api-legacy'] : 'off'}">Enable legacy mode
</label> </label>
</div> </div>
<div class="field"> <div class="field">

View file

@ -1,5 +1,5 @@
<?php <?php
require __DIR__ . "/../vendor/autoload.php"; require __DIR__ . "/vendor/autoload.php";
// LOAD DOTENV // LOAD DOTENV
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..'); $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
@ -9,6 +9,6 @@ $dotenv->safeLoad();
$router = new Bramus\Router\Router(); $router = new Bramus\Router\Router();
$router->setNamespace('\App\Controllers'); $router->setNamespace('\App\Controllers');
require __DIR__ . '/../routes.php'; require __DIR__ . '/routes.php';
$router->run(); $router->run();

View file

@ -2,8 +2,8 @@
"name": "proxitok-scss", "name": "proxitok-scss",
"private": true, "private": true,
"scripts": { "scripts": {
"bulma": "sass --style=compressed bulma.scss ../public/styles/vendor/bulma.min.css", "bulma": "sass --style=compressed bulma.scss ./styles/vendor/bulma.min.css",
"fa": "sass --style=compressed fontawesome.scss ../public/styles/vendor/fontawesome.min.css" "fa": "sass --style=compressed fontawesome.scss ./styles/vendor/fontawesome.min.css"
}, },
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^6.0.0", "@fortawesome/fontawesome-free": "^6.0.0",

8
setup/nginx.conf Normal file
View file

@ -0,0 +1,8 @@
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /.env {
deny all;
return 404;
}

View file

@ -4,7 +4,7 @@
<p class="title">{$feed->info->detail->title}</p> <p class="title">{$feed->info->detail->title}</p>
<p class="subtitle">{$feed->info->detail->desc}</p> <p class="subtitle">{$feed->info->detail->desc}</p>
<p>Videos: {number($feed->info->stats->videoCount)} / Views: {number($feed->info->stats->viewCount)}</p> <p>Videos: {number($feed->info->stats->videoCount)} / Views: {number($feed->info->stats->viewCount)}</p>
<a href="{path('tag/' . $feed->info->detail->title . '/rss')}">RSS</a> <a href="{path('/tag/' . $feed->info->detail->title . '/rss')}">RSS</a>
{/block} {/block}
{block content} {block content}