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
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
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:
```bash
php -S localhost:8080 -t public
php -S localhost:8080
```
## Configuration
### .env
Move the .env.example file to .env and modify it.
### Cache engines
Available cache engines:
* redis: Writes response to Redis
@ -50,21 +48,7 @@ Available cache engines:
You don't have to do anything more
### Nginx
Add the following to your config (you can modify the proxitok part if you have or not a subdir):
```
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;
}
```
You can get a config example on /setup/nginx.conf
## TODO
* 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);
}
static private function redirect() {
$url = Misc::url('/settings');
header("Location: {$url}");
}
static public function proxy() {
if (in_array(Cookies::PROXY, $_POST)) {
foreach (Cookies::PROXY as $proxy_element) {
Cookies::set($proxy_element, $_POST[$proxy_element]);
}
}
$url = Misc::url('/settings');
header("Location: {$url}");
self::redirect();
}
static public function api() {
$_POST['legacy'] ?? Cookies::set('api-legacy', '1');
$url = Misc::url('/settings');
header("Location: {$url}");
$legacy = 'off';
if (isset($_POST['api-legacy'])) {
$legacy = 'on';
}
Cookies::set('api-legacy', $legacy);
self::redirect();
}
}

View file

@ -78,8 +78,7 @@ class Misc {
}
// Legacy mode
$_COOKIE['enable_legacy'] ?? $legacy = true; // User level
$legacy = self::env('FORCE_LEGACY', false); // Instance level (has priority over user)
$legacy = self::env('FORCE_LEGACY', false) || isset($_COOKIE['api-legacy']) && $_COOKIE['api-legacy'] === 'on';
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">
<div class="field">
<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>
</div>
<div class="field">

View file

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

View file

@ -2,8 +2,8 @@
"name": "proxitok-scss",
"private": true,
"scripts": {
"bulma": "sass --style=compressed bulma.scss ../public/styles/vendor/bulma.min.css",
"fa": "sass --style=compressed fontawesome.scss ../public/styles/vendor/fontawesome.min.css"
"bulma": "sass --style=compressed bulma.scss ./styles/vendor/bulma.min.css",
"fa": "sass --style=compressed fontawesome.scss ./styles/vendor/fontawesome.min.css"
},
"dependencies": {
"@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="subtitle">{$feed->info->detail->desc}</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 content}