mirror of
https://github.com/flextype/flextype.git
synced 2025-08-16 18:14:04 +02:00
feat(core): modify response headers for all API's
This commit is contained in:
@@ -57,15 +57,23 @@ $app->get('/api/delivery/entries', function (Request $request, Response $respons
|
||||
Filesystem::write($delivery_entries_token_file_path, $flextype['parser']->encode(array_replace_recursive($delivery_entries_token_file_data, ['calls' => $delivery_entries_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
// Return response
|
||||
return $response->withJson($data, $response_code);
|
||||
return $response
|
||||
->withJson($data, $response_code)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
} else {
|
||||
return $response->withJson(["detail" => "Incorrect authentication credentials."], 401);
|
||||
return $response
|
||||
->withJson(["detail" => "Incorrect authentication credentials."], 401)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
} else {
|
||||
return $response->withJson(["detail" => "Incorrect authentication credentials."], 401);
|
||||
return $response
|
||||
->withJson(["detail" => "Incorrect authentication credentials."], 401)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
} else {
|
||||
return $response->withJson(["detail" => "Incorrect authentication credentials."], 401);
|
||||
return $response
|
||||
->withJson(["detail" => "Incorrect authentication credentials."], 401)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
});
|
||||
|
@@ -48,20 +48,31 @@ $app->get('/api/delivery/images/{path:.+}', function (Request $request, Response
|
||||
Filesystem::write($delivery_images_token_file_path, $flextype['parser']->encode(array_replace_recursive($delivery_images_token_file_data, ['calls' => $delivery_images_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
if (Filesystem::has(PATH['uploads'] . '/entries/' . $args['path'])) {
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
return $flextype['images']->getImageResponse($args['path'], $_GET);
|
||||
} else {
|
||||
return $response->withJson([], 404);
|
||||
return $response
|
||||
->withJson([], 404)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return $response->withJson(["detail" => "Incorrect authentication credentials."], 401);
|
||||
return $response
|
||||
->withJson(["detail" => "Incorrect authentication credentials."], 401)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
} else {
|
||||
return $response->withJson(["detail" => "Incorrect authentication credentials."], 401);
|
||||
return $response
|
||||
->withJson(["detail" => "Incorrect authentication credentials."], 401)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
|
||||
return $response->withStatus(404);
|
||||
return $response
|
||||
->withStatus(404)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
} else {
|
||||
return $response->withJson(["detail" => "Incorrect authentication credentials."], 401);
|
||||
return $response
|
||||
->withJson(["detail" => "Incorrect authentication credentials."], 401)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
});
|
||||
|
@@ -53,15 +53,23 @@ $app->get('/api/delivery/registry', function (Request $request, Response $respon
|
||||
Filesystem::write($delivery_registry_token_file_path, $flextype['parser']->encode(array_replace_recursive($delivery_registry_token_file_data, ['calls' => $delivery_registry_token_file_data['calls'] + 1]), 'yaml'));
|
||||
|
||||
// Return response
|
||||
return $response->withJson($data, 200);
|
||||
return $response
|
||||
->withJson($data, 200)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
} else {
|
||||
return $response->withJson(["detail" => "Incorrect authentication credentials."], 401);
|
||||
return $response
|
||||
->withJson(["detail" => "Incorrect authentication credentials."], 401)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
} else {
|
||||
return $response->withJson(["detail" => "Incorrect authentication credentials."], 401);
|
||||
return $response
|
||||
->withJson(["detail" => "Incorrect authentication credentials."], 401)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
} else {
|
||||
return $response->withJson(["detail" => "Incorrect authentication credentials."], 401);
|
||||
return $response
|
||||
->withJson(["detail" => "Incorrect authentication credentials."], 401)
|
||||
->withHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
});
|
||||
|
@@ -177,18 +177,6 @@ foreach ($shortcodes_extensions as $shortcodes_extension) {
|
||||
}
|
||||
}
|
||||
|
||||
$app->options('/{routes:.+}', function ($request, $response, $args) {
|
||||
return $response;
|
||||
});
|
||||
|
||||
$app->add(function ($req, $res, $next) {
|
||||
$response = $next($req, $res);
|
||||
return $response
|
||||
->withHeader('Access-Control-Allow-Origin', '*')
|
||||
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
|
||||
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
||||
});
|
||||
|
||||
/**
|
||||
* Init plugins
|
||||
*/
|
||||
@@ -199,13 +187,6 @@ $flextype['plugins']->init($flextype, $app);
|
||||
*/
|
||||
$flextype['themes']->init($flextype, $app);
|
||||
|
||||
// Catch-all route to serve a 404 Not Found page if none of the routes match
|
||||
// NOTE: make sure this route is defined last
|
||||
$app->map(['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], '/{routes:.+}', function($req, $res) {
|
||||
$handler = $this->notFoundHandler; // handle using the default Slim page not found handler
|
||||
return $handler($req, $res);
|
||||
});
|
||||
|
||||
/**
|
||||
* Run application
|
||||
*/
|
||||
|
Reference in New Issue
Block a user