From 477efe848650a8905f1e5cde99931ed9a567b794 Mon Sep 17 00:00:00 2001 From: Pablo Ferreiro Date: Mon, 3 Jan 2022 14:32:35 +0100 Subject: [PATCH] Nginx config example and relative path --- README.md | 25 +++++++++++++++++++++++++ index.php | 10 +++++++--- views/navbar.latte | 4 ++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 588a8ad..951f6c9 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,36 @@ Then you can run it using for example the PHP Development Server with: php -S localhost:8080 ``` +## Configuration +### .env +Move the .env.example file to .env and modify it. + +### Apache +If you are using Apache you don't have to do anything more + +### Nginx +Add the following to your config (you can modify the tiktok-viewer part if you have or not a subdir): +``` +location /tiktok-viewer { + return 302 $scheme://$host/tiktok-viewer/; +} + +location /tiktok-viewer/ { + try_files $uri $uri/ /tiktok-viewer/index.php?$query_string; +} + +location /tiktok-viewer/.env { + deny all; + return 404; +} +``` + ## Known issues * Right now there is an error when trying to fetch the desired user, there is already a pull request not merged yet fixing this issue on the TikTokApi repo, you can check it out [here](https://github.com/ssovit/TikTok-API-PHP/pull/43) ## TODO * Allow searching for just one video using the ID +* Code cleanup ## Credits * [TikTok-API-PHP](https://github.com/ssovit/TikTok-API-PHP) diff --git a/index.php b/index.php index 03b8826..1c241be 100644 --- a/index.php +++ b/index.php @@ -9,7 +9,7 @@ $dotenv = Dotenv\Dotenv::createImmutable(__DIR__); $dotenv->load(); function getSubdir(): string { - return $_ENV['APP_SUBDIR'] ? $_ENV['APP_SUBDIR'] : '/'; + return $_ENV['APP_SUBDIR'] ? $_ENV['APP_SUBDIR'] : ''; } function getApi(array $proxy_elements): \Sovit\TikTok\Api { @@ -25,13 +25,17 @@ function getApi(array $proxy_elements): \Sovit\TikTok\Api { } function getLatte(): \Latte\Engine { + $subdir = getSubdir(); $latte = new Latte\Engine; $latte->setTempDirectory('./cache/views'); - $latte->addFunction('assets', function (string $name, string $type) { - $subdir = getSubdir(); + $latte->addFunction('assets', function (string $name, string $type) use ($subdir) { $path = "{$subdir}/{$type}/{$name}"; return $path; }); + $latte->addFunction('path', function (string $name) use ($subdir) { + $path = "{$subdir}/{$name}"; + return $path; + }); return $latte; } diff --git a/views/navbar.latte b/views/navbar.latte index 35c6da9..1c0be42 100644 --- a/views/navbar.latte +++ b/views/navbar.latte @@ -9,8 +9,8 @@