From 6900fd572f661857aab9394874742d5ad10509d9 Mon Sep 17 00:00:00 2001 From: Julien Nahum Date: Tue, 2 Jan 2024 19:03:14 +0100 Subject: [PATCH] Remove axios and commit backend changes to sitemap --- app/Http/Controllers/SitemapController.php | 60 ++++------------------ client/stores/auth.js | 5 +- routes/api.php | 2 + routes/web.php | 3 +- 4 files changed, 16 insertions(+), 54 deletions(-) diff --git a/app/Http/Controllers/SitemapController.php b/app/Http/Controllers/SitemapController.php index 1c624e0..712073e 100644 --- a/app/Http/Controllers/SitemapController.php +++ b/app/Http/Controllers/SitemapController.php @@ -9,62 +9,24 @@ use App\Models\Template; class SitemapController extends Controller { - /** - * Contains route name and the associated priority - * - * @var array - */ - protected $urls = [ - ['/', 1], - ['/pricing', 0.9], - ['/privacy-policy', 0.5], - ['/terms-conditions', 0.5], - ['/login', 0.4], - ['/register', 0.4], - ['/password/reset', 0.3], - ['/form-templates', 0.9], - ]; - public function getSitemap(Request $request) + public function index(Request $request) { - $sitemap = Sitemap::create(); - foreach ($this->urls as $url) { - $sitemap->add($this->createUrl($url[0], $url[1])); - } - $this->addTemplatesUrls($sitemap); - $this->addTemplatesTypesUrls($sitemap); - $this->addTemplatesIndustriesUrls($sitemap); - - return $sitemap->toResponse($request); + return [ + ...$this->getTemplatesUrls() + ]; } - private function createUrl($url, $priority, $frequency = 'daily') + private function getTemplatesUrls() { - return Url::create($url)->setPriority($priority)->setChangeFrequency($frequency); - } - - private function addTemplatesUrls(Sitemap $sitemap) - { - Template::where('publicly_listed', true)->chunk(100, function ($templates) use ($sitemap) { + $urls = []; + Template::where('publicly_listed', true)->chunk(100, function ($templates) use (&$urls) { foreach ($templates as $template) { - $sitemap->add($this->createUrl('/form-templates/' . $template->slug, 0.8)); + $urls[] = [ + 'loc' => '/templates/' . $template->slug + ]; } }); - } - - private function addTemplatesTypesUrls(Sitemap $sitemap) - { - $types = json_decode(file_get_contents(resource_path('data/forms/templates/types.json')), true); - foreach ($types as $type) { - $sitemap->add($this->createUrl('/form-templates/types/' . $type['slug'], 0.7)); - } - } - - private function addTemplatesIndustriesUrls(Sitemap $sitemap) - { - $industries = json_decode(file_get_contents(resource_path('data/forms/templates/industries.json')), true); - foreach ($industries as $industry) { - $sitemap->add($this->createUrl('/form-templates/industries/' . $industry['slug'], 0.7)); - } + return $urls; } } diff --git a/client/stores/auth.js b/client/stores/auth.js index 52472e4..b84ad56 100644 --- a/client/stores/auth.js +++ b/client/stores/auth.js @@ -1,5 +1,4 @@ import {defineStore} from 'pinia' -import axios from 'axios' export const useAuthStore = defineStore('auth', { state: () => { @@ -88,8 +87,8 @@ export const useAuthStore = defineStore('auth', { }, async fetchOauthUrl(provider) { - const {data} = await axios.post(`/api/oauth/${provider}`) - return data.url + // const {data} = await axios.post(`/api/oauth/${provider}`) + // return data.url } } }) diff --git a/routes/api.php b/routes/api.php index 5368579..063589a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -167,6 +167,8 @@ Route::prefix('content')->name('content.')->group(function () { Route::get('changelog/entries', [\App\Http\Controllers\Content\ChangelogController::class, 'index'])->name('changelog.entries'); }); +Route::get('/sitemap-urls', [\App\Http\Controllers\SitemapController::class, 'index'])->name('sitemap.index'); + // Templates Route::prefix('templates')->group(function () { Route::get('/', [TemplateController::class, 'index'])->name('templates.index'); diff --git a/routes/web.php b/routes/web.php index e74bf09..05896a9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -28,6 +28,7 @@ Route::post( '/upload-file', [\App\Http\Controllers\Content\FileUploadController::class, 'upload'] )->middleware([]); + Route::get('local/temp/{path}', function (Request $request, string $path){ if (!$request->hasValidSignature()) { abort(401); @@ -37,7 +38,5 @@ Route::get('local/temp/{path}', function (Request $request, string $path){ return $response; })->where('path', '(.*)')->name('local.temp'); -Route::get('/sitemap.xml', [\App\Http\Controllers\SitemapController::class, 'getSitemap'])->name('sitemap'); - Route::get('caddy/ask-certificate/{secret?}', [\App\Http\Controllers\CaddyController::class, 'ask']) ->name('caddy.ask')->middleware(\App\Http\Middleware\CaddyRequestMiddleware::class);