Create a gist now

Instantly share code, notes, and snippets.

@msyk /router.php forked from matsuo/router.php
Last active May 15, 2017

What would you like to do?
ローカルでFileMaker Data APIを使って開発する際に利用するPHPのビルトインサーバー用ルータースクリプト
<?php
$url = "http://127.0.0.1:3000" . $_SERVER['REQUEST_URI'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
}
if (in_array($_SERVER['REQUEST_METHOD'], array('PUT', 'DELETE'))) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']);
}
if (in_array($_SERVER['REQUEST_METHOD'], array('POST', 'PUT'))) {
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents("php://input"));
}
$headers = array(
'X-Forwarded-For: ' . $_SERVER['REMOTE_ADDR'],
);
if (isset($_SERVER['CONTENT_TYPE'])) {
$headers[] = 'Content-Type: ' . $_SERVER['CONTENT_TYPE'];
}
if (isset($_SERVER['HTTP_FM_DATA_TOKEN'])) {
$headers[] = 'FM-Data-token: ' . $_SERVER['HTTP_FM_DATA_TOKEN'];
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$html = curl_exec($ch);
echo $html;
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment