Fix cors
This commit is contained in:
parent
a51abc7ec6
commit
5f71c3a058
|
@ -24,4 +24,5 @@ dist-ssr
|
||||||
*.sw?
|
*.sw?
|
||||||
|
|
||||||
# php
|
# php
|
||||||
|
/public/vendor
|
||||||
/api/vendor
|
/api/vendor
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
<Files ".env">
|
|
||||||
Order Allow,Deny
|
|
||||||
Deny from all
|
|
||||||
</Files>
|
|
||||||
|
|
||||||
<IfModule mod_rewrite.c>
|
|
||||||
RewriteEngine On
|
|
||||||
|
|
||||||
# RewriteCond %{HTTPS} off
|
|
||||||
# RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
|
|
||||||
|
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
|
||||||
RewriteCond %{REQUEST_FILENAME} !-d
|
|
||||||
RewriteRule . index.php [L]
|
|
||||||
</IfModule>
|
|
|
@ -1,59 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
function remoteFileExists($url) {
|
|
||||||
$curl = curl_init($url);
|
|
||||||
|
|
||||||
//don't fetch the actual page, you only want to check the connection is ok
|
|
||||||
curl_setopt($curl, CURLOPT_NOBODY, true);
|
|
||||||
|
|
||||||
//do request
|
|
||||||
$result = curl_exec($curl);
|
|
||||||
|
|
||||||
$ret = false;
|
|
||||||
|
|
||||||
//if request did not fail
|
|
||||||
if ($result !== false) {
|
|
||||||
//if request was ok, check response code
|
|
||||||
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
||||||
|
|
||||||
if ($statusCode == 200) {
|
|
||||||
$ret = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
curl_close($curl);
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
|
|
||||||
"post" => function($data, $headers, $db) {
|
|
||||||
$imagesHostName = 'https://geohry.skolazdola.cz/';
|
|
||||||
|
|
||||||
if(!isset($data['gameurl']) || empty($data['gameurl'])) return [
|
|
||||||
"error" => "Property 'gameurl' is not set."
|
|
||||||
];
|
|
||||||
|
|
||||||
$gameUrl = $data['gameurl'];
|
|
||||||
|
|
||||||
$gameDetails = $db->select('games4', '*', [
|
|
||||||
'url' => $gameUrl
|
|
||||||
])[0];
|
|
||||||
|
|
||||||
$gameDetails["questions"] = $db->select('questions4', '*', [
|
|
||||||
'url' => $gameUrl
|
|
||||||
]);
|
|
||||||
|
|
||||||
$thumbnailPath = "{$imagesHostName}/games/{$gameUrl}/intro.jpg";
|
|
||||||
$gameDetails["thumbnail"] = remoteFileExists($thumbnailPath) ? $thumbnailPath : null;
|
|
||||||
|
|
||||||
foreach($gameDetails["questions"] as &$question) {
|
|
||||||
$questionThumbnailPath = "{$imagesHostName}/games/{$gameUrl}/" . $question["uniqid"] . ".jpg";
|
|
||||||
$question["thumbnail"] = remoteFileExists($questionThumbnailPath) ? $questionThumbnailPath : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $gameDetails;
|
|
||||||
}
|
|
||||||
|
|
||||||
];
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"vendor-dir": "api/vendor"
|
"vendor-dir": "public/vendor"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"bramus/router": "1.5",
|
"bramus/router": "1.5",
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"name": "geohry",
|
"name": "geohry",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^0.27.2",
|
||||||
"svelte-routing": "^1.6.0"
|
"svelte-routing": "^1.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -95,6 +96,11 @@
|
||||||
"node": ">= 8"
|
"node": ">= 8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/asynckit": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
|
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||||
|
},
|
||||||
"node_modules/autoprefixer": {
|
"node_modules/autoprefixer": {
|
||||||
"version": "10.4.7",
|
"version": "10.4.7",
|
||||||
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.7.tgz",
|
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.7.tgz",
|
||||||
|
@ -128,6 +134,15 @@
|
||||||
"postcss": "^8.1.0"
|
"postcss": "^8.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/axios": {
|
||||||
|
"version": "0.27.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz",
|
||||||
|
"integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.14.9",
|
||||||
|
"form-data": "^4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/balanced-match": {
|
"node_modules/balanced-match": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||||
|
@ -245,6 +260,17 @@
|
||||||
"fsevents": "~2.3.2"
|
"fsevents": "~2.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/combined-stream": {
|
||||||
|
"version": "1.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
|
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||||
|
"dependencies": {
|
||||||
|
"delayed-stream": "~1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/concat-map": {
|
"node_modules/concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
|
@ -282,6 +308,14 @@
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/delayed-stream": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/detect-indent": {
|
"node_modules/detect-indent": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz",
|
||||||
|
@ -685,6 +719,38 @@
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/follow-redirects": {
|
||||||
|
"version": "1.15.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz",
|
||||||
|
"integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "individual",
|
||||||
|
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"debug": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/form-data": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||||
|
"dependencies": {
|
||||||
|
"asynckit": "^0.4.0",
|
||||||
|
"combined-stream": "^1.0.8",
|
||||||
|
"mime-types": "^2.1.12"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/fraction.js": {
|
"node_modules/fraction.js": {
|
||||||
"version": "4.2.0",
|
"version": "4.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz",
|
||||||
|
@ -888,6 +954,25 @@
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/mime-db": {
|
||||||
|
"version": "1.52.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||||
|
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/mime-types": {
|
||||||
|
"version": "2.1.35",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||||
|
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||||
|
"dependencies": {
|
||||||
|
"mime-db": "1.52.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/min-indent": {
|
"node_modules/min-indent": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz",
|
||||||
|
@ -1515,6 +1600,11 @@
|
||||||
"picomatch": "^2.0.4"
|
"picomatch": "^2.0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"asynckit": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
|
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||||
|
},
|
||||||
"autoprefixer": {
|
"autoprefixer": {
|
||||||
"version": "10.4.7",
|
"version": "10.4.7",
|
||||||
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.7.tgz",
|
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.7.tgz",
|
||||||
|
@ -1529,6 +1619,15 @@
|
||||||
"postcss-value-parser": "^4.2.0"
|
"postcss-value-parser": "^4.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"axios": {
|
||||||
|
"version": "0.27.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz",
|
||||||
|
"integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==",
|
||||||
|
"requires": {
|
||||||
|
"follow-redirects": "^1.14.9",
|
||||||
|
"form-data": "^4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||||
|
@ -1600,6 +1699,14 @@
|
||||||
"readdirp": "~3.6.0"
|
"readdirp": "~3.6.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"combined-stream": {
|
||||||
|
"version": "1.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
|
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||||
|
"requires": {
|
||||||
|
"delayed-stream": "~1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
|
@ -1626,6 +1733,11 @@
|
||||||
"integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==",
|
"integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"delayed-stream": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
|
||||||
|
},
|
||||||
"detect-indent": {
|
"detect-indent": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.1.0.tgz",
|
||||||
|
@ -1833,6 +1945,21 @@
|
||||||
"to-regex-range": "^5.0.1"
|
"to-regex-range": "^5.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"follow-redirects": {
|
||||||
|
"version": "1.15.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz",
|
||||||
|
"integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA=="
|
||||||
|
},
|
||||||
|
"form-data": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||||
|
"requires": {
|
||||||
|
"asynckit": "^0.4.0",
|
||||||
|
"combined-stream": "^1.0.8",
|
||||||
|
"mime-types": "^2.1.12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"fraction.js": {
|
"fraction.js": {
|
||||||
"version": "4.2.0",
|
"version": "4.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz",
|
||||||
|
@ -1986,6 +2113,19 @@
|
||||||
"sourcemap-codec": "^1.4.8"
|
"sourcemap-codec": "^1.4.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"mime-db": {
|
||||||
|
"version": "1.52.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||||
|
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="
|
||||||
|
},
|
||||||
|
"mime-types": {
|
||||||
|
"version": "2.1.35",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||||
|
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||||
|
"requires": {
|
||||||
|
"mime-db": "1.52.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"min-indent": {
|
"min-indent": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz",
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"php": "php -S localhost:8000 -t ./api"
|
"php": "php -S localhost:8000 -t ./public"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/vite-plugin-svelte": "^1.0.1",
|
"@sveltejs/vite-plugin-svelte": "^1.0.1",
|
||||||
|
@ -20,6 +20,7 @@
|
||||||
"vite": "^3.0.0"
|
"vite": "^3.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^0.27.2",
|
||||||
"svelte-routing": "^1.6.0"
|
"svelte-routing": "^1.6.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
<Files ".env">
|
<Files "api/.env">
|
||||||
Order Allow,Deny
|
Order Allow,Deny
|
||||||
Deny from all
|
Deny from all
|
||||||
</Files>
|
</Files>
|
||||||
|
|
||||||
<IfModule mod_rewrite.c>
|
RewriteEngine On
|
||||||
RewriteEngine On
|
|
||||||
|
|
||||||
# RewriteCond %{HTTPS} off
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
# RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteRule . index.php [L]
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
|
||||||
RewriteCond %{REQUEST_FILENAME} !-d
|
|
||||||
RewriteRule . index.php [L]
|
|
||||||
</IfModule>
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require __DIR__ . '/vendor/autoload.php';
|
|
||||||
require __DIR__ . '/utils/cors.php';
|
|
||||||
|
|
||||||
use Medoo\Medoo;
|
use Medoo\Medoo;
|
||||||
|
|
||||||
cors();
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||||
|
@ -16,8 +11,6 @@ function env($key) {
|
||||||
return array_key_exists($key, $_ENV) ? $_ENV[$key] : null;
|
return array_key_exists($key, $_ENV) ? $_ENV[$key] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$router = new \Bramus\Router\Router();
|
|
||||||
|
|
||||||
$database = new Medoo([
|
$database = new Medoo([
|
||||||
'type' => 'mysql',
|
'type' => 'mysql',
|
||||||
'host' => env("DB_HOST"),
|
'host' => env("DB_HOST"),
|
||||||
|
@ -49,7 +42,10 @@ $getFolderContentUtil = function($dir) use($routesDirectory, &$getFolderContentU
|
||||||
$router->{$key}(str_replace(".php", '', $pathWithoutRelativeRoot), function() use($router, $fn, $data, $error, $database) {
|
$router->{$key}(str_replace(".php", '', $pathWithoutRelativeRoot), function() use($router, $fn, $data, $error, $database) {
|
||||||
$responseResult = $fn($data, getallheaders(), $database, $error, $router);
|
$responseResult = $fn($data, getallheaders(), $database, $error, $router);
|
||||||
if($responseResult) {
|
if($responseResult) {
|
||||||
echo json_encode($responseResult);
|
$responseResult["status"] = array_key_exists("status", $responseResult) ? $responseResult["status"] : 200;
|
||||||
|
http_response_code($responseResult["status"]);
|
||||||
|
echo json_encode($responseResult["data"]);
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
"post" => function($data, $headers, $db) {
|
||||||
|
function remoteFileExists($url) {
|
||||||
|
$curl = curl_init($url);
|
||||||
|
|
||||||
|
//don't fetch the actual page, you only want to check the connection is ok
|
||||||
|
curl_setopt($curl, CURLOPT_NOBODY, true);
|
||||||
|
|
||||||
|
//do request
|
||||||
|
$result = curl_exec($curl);
|
||||||
|
|
||||||
|
$ret = false;
|
||||||
|
|
||||||
|
//if request did not fail
|
||||||
|
if ($result !== false) {
|
||||||
|
//if request was ok, check response code
|
||||||
|
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
|
|
||||||
|
if ($statusCode == 200) {
|
||||||
|
$ret = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_close($curl);
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
$imagesHostName = 'https://geohry.skolazdola.cz/';
|
||||||
|
|
||||||
|
if(!isset($data['gameurl']) || empty($data['gameurl'])) return [
|
||||||
|
"data" => [
|
||||||
|
"success" => false,
|
||||||
|
"message" => "Property 'gameurl' is not set."
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$gameUrl = $data['gameurl'];
|
||||||
|
|
||||||
|
$gameDetails = $db->select('games4', '*', [
|
||||||
|
'url' => $gameUrl
|
||||||
|
]);
|
||||||
|
|
||||||
|
if(!$gameDetails) return [
|
||||||
|
"data" => [
|
||||||
|
"success" => false,
|
||||||
|
"message" => "Invalid 'gameurl'."
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$gameDetails = $gameDetails[0];
|
||||||
|
|
||||||
|
$gameDetails["questions"] = $db->select('questions4', '*', [
|
||||||
|
'url' => $gameUrl
|
||||||
|
]);
|
||||||
|
|
||||||
|
$thumbnailPath = "{$imagesHostName}/games/{$gameUrl}/intro.jpg";
|
||||||
|
$gameDetails["thumbnail"] = remoteFileExists($thumbnailPath) ? $thumbnailPath : null;
|
||||||
|
|
||||||
|
foreach($gameDetails["questions"] as &$question) {
|
||||||
|
$questionThumbnailPath = "{$imagesHostName}/games/{$gameUrl}/" . $question["uniqid"] . ".jpg";
|
||||||
|
$question["thumbnail"] = remoteFileExists($questionThumbnailPath) ? $questionThumbnailPath : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
"success" => true,
|
||||||
|
"data" => $gameDetails
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
];
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An example CORS-compliant method. It will allow any GET, POST, or OPTIONS requests from any
|
* An example CORS-compliant method. It will allow any GET, POST, or OPTIONS requests from any
|
||||||
* origin.
|
* origin.
|
||||||
|
@ -18,20 +17,21 @@ function cors() {
|
||||||
// Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
|
// Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
|
||||||
// you want to allow, and if so:
|
// you want to allow, and if so:
|
||||||
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
|
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
|
||||||
header('Access-Control-Allow-Credentials: true');
|
header("Access-Control-Allow-Credentials: true");
|
||||||
header('Access-Control-Max-Age: 86400'); // cache for 1 day
|
header("Access-Control-Allow-Header: *");
|
||||||
|
header("Access-Control-Max-Age: 86400"); // cache for 1 day
|
||||||
}
|
}
|
||||||
|
|
||||||
// Access-Control headers are received during OPTIONS requests
|
// Access-Control headers are received during OPTIONS requests
|
||||||
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
||||||
|
|
||||||
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
|
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
|
||||||
// may also be using PUT, PATCH, HEAD etc
|
|
||||||
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
|
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
|
||||||
|
|
||||||
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
|
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
|
||||||
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
|
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
|
||||||
|
|
||||||
|
header("Access-Control-Allow-Origin: *");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,30 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once(__DIR__ . '/index.html');
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
|
require __DIR__ . '/cors.php';
|
||||||
|
|
||||||
|
cors();
|
||||||
|
|
||||||
|
$router = new \Bramus\Router\Router();
|
||||||
|
$router->setBasePath('/');
|
||||||
|
|
||||||
|
$router->mount("/api", function() use($router) {
|
||||||
|
require_once __DIR__ . '/api/index.php';
|
||||||
|
});
|
||||||
|
|
||||||
|
$router->set404('/api(/.*)?', function() {
|
||||||
|
header('HTTP/1.1 404 Not Found');
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
"message" => "Route not defined."
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
$router->get("/.*", function() {
|
||||||
|
header('Content-Type: text/html; charset=UTF-8');
|
||||||
|
echo "frontend!";
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$router->run();
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
|
export const hostName = 'https://erant.cz/api'
|
||||||
|
|
||||||
async function send({ method, path, body, token, headers }) {
|
async function send({ method, path, body, token, headers }) {
|
||||||
const opts = { method, headers: {} }
|
const opts = { method, headers: new Headers(), mode: 'cors' }
|
||||||
opts.headers['Content-Type'] = 'application/json'
|
opts.headers.append('Content-Type', 'application/json')
|
||||||
|
opts.headers.append('Access-Control-Allow-Origin', '*')
|
||||||
|
|
||||||
if (body) {
|
if (body) {
|
||||||
opts.body = JSON.stringify(body)
|
opts.body = JSON.stringify(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headers) {
|
if (headers) {
|
||||||
opts.headers = Object.fromEntries(headers.map(({ key, value }) => [key, value]))
|
for (const [k, v] of Object.entries(headers)) {
|
||||||
|
opts.headers.append(k, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
|
@ -53,5 +58,3 @@ export function put(
|
||||||
) {
|
) {
|
||||||
return send({ method: 'PUT', path, body, token, headers })
|
return send({ method: 'PUT', path, body, token, headers })
|
||||||
}
|
}
|
||||||
|
|
||||||
export const hostName = 'http://localhost:8000'
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
let assets = Array.from(Array(4).keys()).map((_, i) => `/assets/temp/kar${i + 1}.png`)
|
let assets = Array.from(Array(4).keys()).map((_, i) => `/assets/temp/kar${i + 1}.png`)
|
||||||
|
|
||||||
;(async () => {
|
;(async () => {
|
||||||
console.log(api.hostName)
|
|
||||||
const gameData = await api.post(`${api.hostName}/game/details`, {
|
const gameData = await api.post(`${api.hostName}/game/details`, {
|
||||||
gameurl: 'pisek-mesto-kralovske',
|
gameurl: 'pisek-mesto-kralovske',
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue