Add nelmio/cors-bundle - Add CORS support for Front-end requests.

This commit is contained in:
2024-05-04 01:44:22 +02:00
parent 15a884fafa
commit a4ec188cff
10 changed files with 112 additions and 14 deletions
+4
View File
@@ -28,3 +28,7 @@ APP_SECRET=d130654a5d6a8ab5945b20b22dfeee74
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://app:[email protected]:54195/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###
###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
###< nelmio/cors-bundle ###
+1 -1
View File
@@ -16,7 +16,7 @@ docker compose build --no-cache
Start Containers:
```
docker compose up --pull always -d --wait
docker compose --env-file .\.env.local up -d --watch
docker compose --env-file .\.env.local up -d --wait
```
Stop containers
+1
View File
@@ -14,6 +14,7 @@
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.1",
"easycorp/easyadmin-bundle": "^4.10",
"nelmio/cors-bundle": "^2.4",
"phpdocumentor/reflection-docblock": "^5.4",
"phpstan/phpdoc-parser": "^1.28",
"runtime/frankenphp-symfony": "^0.2.0",
Generated
+63 -1
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e0a5e615a56df791d0b9a2dbbe533659",
"content-hash": "0422b42b049fb3382babd77edbaac205",
"packages": [
{
"name": "doctrine/cache",
@@ -1320,6 +1320,68 @@
],
"time": "2024-04-19T18:13:15+00:00"
},
{
"name": "nelmio/cors-bundle",
"version": "2.4.0",
"source": {
"type": "git",
"url": "https://github.com/nelmio/NelmioCorsBundle.git",
"reference": "78fcdb91f76b080a1008133def9c7f613833933d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nelmio/NelmioCorsBundle/zipball/78fcdb91f76b080a1008133def9c7f613833933d",
"reference": "78fcdb91f76b080a1008133def9c7f613833933d",
"shasum": ""
},
"require": {
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0"
},
"require-dev": {
"mockery/mockery": "^1.3.6",
"symfony/phpunit-bridge": "^5.4 || ^6.0 || ^7.0"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
},
"autoload": {
"psr-4": {
"Nelmio\\CorsBundle\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nelmio",
"homepage": "http://nelm.io"
},
{
"name": "Symfony Community",
"homepage": "https://github.com/nelmio/NelmioCorsBundle/contributors"
}
],
"description": "Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony application",
"keywords": [
"api",
"cors",
"crossdomain"
],
"support": {
"issues": "https://github.com/nelmio/NelmioCorsBundle/issues",
"source": "https://github.com/nelmio/NelmioCorsBundle/tree/2.4.0"
},
"time": "2023-11-30T16:41:19+00:00"
},
{
"name": "phpdocumentor/reflection-common",
"version": "2.2.0",
+1
View File
@@ -9,4 +9,5 @@ return [
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle::class => ['all' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
];
+15
View File
@@ -0,0 +1,15 @@
nelmio_cors:
defaults:
origin_regex: true
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
allow_headers: ['Content-Type', 'Authorization']
expose_headers: ['Link']
max_age: 3600
paths:
'^/api/':
allow_origin: ['*']
allow_headers: ['*']
allow_methods: ['POST', 'GET']
max_age: 3600
'^/': null
+4 -4
View File
@@ -9,7 +9,7 @@ use App\Repository\ConfigVariableRepository;
class ConfigVariableController extends AbstractController
{
#[Route('/config', name: 'app_config_variable')]
#[Route('/api/config', name: 'app_config_variable')]
public function getAllVariables(ConfigVariableRepository $repo): Response
{
$varList = $repo->findAllVariables();
@@ -17,7 +17,7 @@ class ConfigVariableController extends AbstractController
return $this->json(['results' => $varList]);
}
#[Route('/config/section', name: 'app_config_sections')]
#[Route('/api/config/section', name: 'app_config_sections')]
public function getSections(ConfigVariableRepository $repo): Response
{
$sectionList = $repo->getAllSections();
@@ -30,7 +30,7 @@ class ConfigVariableController extends AbstractController
return $this->json(['results' => $returnList]);
}
#[Route('/config/section/{section}', name: 'app_config_variableBySection')]
#[Route('/api/config/section/{section}', name: 'app_config_variableBySection')]
public function getVariablesBySection(ConfigVariableRepository $repo, string $section): Response
{
if(\is_null($section) || $section == '') {
@@ -42,7 +42,7 @@ class ConfigVariableController extends AbstractController
return $this->json(['results' => $varList]);
}
#[Route('/config/var/{key}', name: 'app_config_variable')]
#[Route('/api/config/var/{key}', name: 'app_config_variable')]
public function getByKey(ConfigVariableRepository $repo, string $key): Response
{
$var = $repo->findVariableByKey($key);
+2 -2
View File
@@ -17,7 +17,7 @@ use Symfony\Component\Serializer\Context\Normalizer\ObjectNormalizerContextBuild
class RoomCategoryController extends AbstractController
{
#[Route('/room/category', name: 'app_room_AllCategories')]
#[Route('/api/room/category', name: 'app_room_AllCategories')]
public function getAll(RoomCategoryRepository $catRepo): Response
{
$catList = $catRepo->findAll();
@@ -25,7 +25,7 @@ class RoomCategoryController extends AbstractController
return $this->json(["results" => $catList]);
}
#[Route('/room/category/{id}', name: 'app_room_category')]
#[Route('/api/room/category/{id}', name: 'app_room_category')]
public function getById(RoomCategory $category): Response
{
return $this->json($category);
+9 -6
View File
@@ -13,7 +13,7 @@ use Symfony\Component\Routing\Attribute\Route;
class SearchRoomsController extends AbstractController
{
#[Route('/search/availability', name: 'app_search_availability')]
#[Route('/api/search/availability', name: 'app_search_availability')]
public function getAvailabilityForPeriod(Request $request, RoomAvailabilityRepository $repoAvailability): Response
{
$payload = $request->toArray();
@@ -30,7 +30,7 @@ class SearchRoomsController extends AbstractController
return $this->json($rs);
}
#[Route('/search/availabilityDetails', name: 'app_search_availabilityDetails')]
#[Route('/api/search/availabilityDetails', name: 'app_search_availabilityDetails')]
public function getAvailabilityForPeriodDetails(Request $request, RoomAvailabilityRepository $repoAvailability): Response
{
$payload = $request->toArray();
@@ -47,8 +47,8 @@ class SearchRoomsController extends AbstractController
return $this->json($rs);
}
#[Route('/search/fares', name: 'app_search_faresForCategory')]
public function getFaresForCategoryOnPeriod(Request $request, RoomCategoryRepository $repoCat): Response
#[Route('/api/search/fares', name: 'app_search_faresForCategory')]
public function getFaresForCategoryOnPeriod(Request $request, RoomCategoryRepository $repoCat, PricesService $priceService): Response
{
$payload = $request->toArray();
if (\is_null($payload)) {
@@ -57,7 +57,8 @@ class SearchRoomsController extends AbstractController
$filter = $payload["filter"];
$catId = $filter["roomCategory"];
if ($repoCat->find($catId) === null) {
$roomCategory = $repoCat->find($catId);
if ($roomCategory === null) {
throw new \Exception('Invalid Category', 400);
}
@@ -69,7 +70,9 @@ class SearchRoomsController extends AbstractController
throw new \Exception('Invalid time interval', 400);
}
return $this->json(["prices" => $dailyPrices]);
$rs = $priceService->getFinalPricesForSearch($roomCategory, $startDate, $endDate);
return $this->json(["prices" => $rs]);
}
#[Route('/search/debug', name: 'app_search_faresDebug')]
+12
View File
@@ -35,6 +35,18 @@
"ref": "b131e6cbfe1b898a508987851963fff485986285"
}
},
"nelmio/cors-bundle": {
"version": "2.4",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.5",
"ref": "6bea22e6c564fba3a1391615cada1437d0bde39c"
},
"files": [
"./config/packages/nelmio_cors.yaml"
]
},
"symfony/console": {
"version": "7.0",
"recipe": {