diff --git a/.gitignore b/.gitignore index b6a4b86d..a66c35ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /node_modules +/bootstrap/cache /public/hot /public/storage /storage/*.key diff --git a/Dockerfile b/Dockerfile index 5d3bdb06..e46c8cbc 100755 --- a/Dockerfile +++ b/Dockerfile @@ -55,10 +55,13 @@ RUN composer install \ --optimize-autoloader RUN mkdir -p \ + storage/app \ storage/framework/cache/data \ storage/framework/sessions \ storage/framework/views \ + storage/logs \ + bootstrap/cache \ && chown -R www-data:www-data storage bootstrap/cache \ - && chmod -R ug+rwx storage bootstrap/cache + && chmod -R ug+rwX storage bootstrap/cache EXPOSE 80 diff --git a/Dockerfile.dev b/Dockerfile.dev deleted file mode 100755 index 6792cad5..00000000 --- a/Dockerfile.dev +++ /dev/null @@ -1,38 +0,0 @@ -FROM php:8.2-apache - -RUN apt-get update \ - && apt-get -y install \ - g++ \ - libcurl4-gnutls-dev \ - libxml2-dev \ - libxslt-dev \ - libzip-dev \ - zlib1g-dev \ - msmtp \ - unzip \ - git \ - ssl-cert \ - locales \ - --no-install-recommends \ - && docker-php-ext-install pdo pdo_mysql mysqli xsl xml zip opcache \ - && a2enmod rewrite ssl proxy proxy_http headers \ - && apt-get purge -y g++ \ - && apt-get autoremove -y \ - && rm -r /var/lib/apt/lists/* - -# Get latest Composer -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer - -# Update the default apache site with the config we created. -ADD docker/apache.dev.conf /etc/apache2/sites-enabled/000-default.conf - -WORKDIR /var/www/html -COPY . /var/www/html - -RUN mkdir -p storage/framework/{sessions,views,cache,cache/data} && \ - chown -R www-data:www-data storage/framework && \ - chmod -R 775 storage - -# RUN php artisan cache:clear && \ -# php artisan config:clear && \ -# php artisan view:clear diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 8658e15b..3b887076 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,13 +2,15 @@ namespace App\Console; +use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; class Kernel extends ConsoleKernel { - private $API_URL; + private $API_URL; /** * The Artisan commands provided by your application. @@ -19,6 +21,22 @@ class Kernel extends ConsoleKernel // ]; + private function getFromApi($url, $file) { + $response = Http::connectTimeout(5) + ->timeout(15) + ->withHeaders([ + 'Host' => $this->API_HOST + ]) + ->get($this->API_URL . $url); + + if ($response->successful()) { + Storage::disk('local')->put( + $file, + $response->body() + ); + } + } + /** * Define the application's command schedule. * @@ -27,39 +45,40 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { - $this->API_URL = env('API_URL', 'https://api.nhgooi.nl/'); - - // Update latest news (3 items) - $schedule->call(function() { - Storage::disk('local')->put('laatste_nieuws.json', file_get_contents($this->API_URL . 'nieuws/overzicht?pagina=1&aantal=3')); - Storage::disk('local')->put('populair_nieuws.json', file_get_contents($this->API_URL . 'nieuws/populair')); - })->everyMinute(); - - // Update now / later - $schedule->call(function() { - Storage::disk('local')->put('nu_straks.json', file_get_contents($this->API_URL . 'programma/schema/nustraks')); - Storage::disk('local')->put('zojuist.json', file_get_contents($this->API_URL . 'programma/schema/recent')); - })->everyMinute(); - - // Update latest podcasts (6 items) - $schedule->call(function() { - Storage::disk('local')->put('laatste_podcasts.json', file_get_contents($this->API_URL . 'podcast/overzicht?pagina=1&aantal=6')); - })->everyMinute(); - - // Update calendar items - $schedule->call(function() { - Storage::disk('local')->put('regioagenda.json', file_get_contents($this->API_URL . 'agenda/overzicht')); - })->everyMinute(); - - // Update blogs - $schedule->call(function() { - Storage::disk('local')->put('blogs.json', file_get_contents($this->API_URL . 'blog/overzicht')); - })->everyMinute(); - - // Update featured images - $schedule->call(function() { - Storage::disk('local')->put('beelden.json', file_get_contents($this->API_URL . 'beelden/overzicht')); - })->everyMinute(); + $this->API_URL = env('API_URL', 'https://api.nhgooi.nl/'); + $this->API_HOST = env('API_HOST', $this->API_URL); + + // Update latest news (3 items) + $schedule->call(function () { + $this->getFromApi('nieuws/overzicht?pagina=1&aantal=3', 'laatste_nieuws.json'); + $this->getFromApi('nieuws/populair', 'populair_nieuws.json'); + })->everyMinute(); + + // Update now / later + $schedule->call(function () { + $this->getFromApi('programma/schema/nustraks', 'nu_straks.json'); + $this->getFromApi('programma/schema/recent', 'zojuist.json'); + })->everyMinute(); + + // Update latest podcasts (6 items) + $schedule->call(function () { + $this->getFromApi('podcast/overzicht?pagina=1&aantal=6', 'laatste_podcasts.json'); + })->everyMinute(); + + // Update calendar items + $schedule->call(function () { + $this->getFromApi('agenda/overzicht', 'regioagenda.json'); + })->everyMinute(); + + // Update blogs + $schedule->call(function () { + $this->getFromApi('blog/overzicht', 'blogs.json'); + })->everyMinute(); + + // Update featured images + $schedule->call(function () { + $this->getFromApi('beelden/overzicht', 'beelden.json'); + })->everyMinute(); } /**