Readded CORS related stuff from private branch.
This commit is contained in:
parent
57afd09ad4
commit
f1245c5a93
2 changed files with 12 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
.apikey
|
.apikey
|
||||||
|
.cors
|
||||||
[Tt]humbs.db
|
[Tt]humbs.db
|
||||||
desktop.ini
|
desktop.ini
|
||||||
$RECYCLE.BIN/
|
$RECYCLE.BIN/
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
define('FNP_API_KEY', __DIR__ . '/../.apikey');
|
define('FNP_API_KEY', __DIR__ . '/../.apikey');
|
||||||
define('FNP_API_URL', 'https://ws.audioscrobbler.com');
|
define('FNP_API_URL', 'https://ws.audioscrobbler.com');
|
||||||
|
define('FNP_ORIGINS', __DIR__ . '/../.cors');
|
||||||
|
|
||||||
define('FNP_FMT_JSON', 'json');
|
define('FNP_FMT_JSON', 'json');
|
||||||
define('FNP_FMT_XML', 'xml');
|
define('FNP_FMT_XML', 'xml');
|
||||||
|
@ -9,6 +10,16 @@ define('FNP_FMTS', [
|
||||||
FNP_FMT_XML => 'application/xml',
|
FNP_FMT_XML => 'application/xml',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if(!empty($_SERVER['HTTP_ORIGIN']) && is_file(FNP_ORIGINS)) {
|
||||||
|
$origin = parse_url($_SERVER['HTTP_ORIGIN'], PHP_URL_HOST);
|
||||||
|
$allowedOrigins = file(FNP_ORIGINS, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
|
|
||||||
|
if(in_array($origin, $allowedOrigins)) {
|
||||||
|
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
|
||||||
|
header('Vary: Origin');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!isset($format))
|
if(!isset($format))
|
||||||
$format = (string)(filter_input(INPUT_GET, 'f') ?? 'json');
|
$format = (string)(filter_input(INPUT_GET, 'f') ?? 'json');
|
||||||
$pretty = !empty($_GET['p']);
|
$pretty = !empty($_GET['p']);
|
||||||
|
|
Loading…
Reference in a new issue