LoginSignup
3
4

More than 5 years have passed since last update.

テスト環境が複数ある時にAPIなどの向き先を自動で変更させるやり方(CodeIgniter編)

Posted at

PCのテスト環境で、ドメインが以下のように複数あり、それぞれAPIもある場合、
www-test1.●●●.net  ⇒  api-test1.●●●.net に向かせたい
www-test2.●●●.net  ⇒  api-test2.●●●.net に向かせたい 
www-test3.●●●.net  ⇒  api-test3.●●●.net に向かせたい

CodeIgniterでは、
application/config/development/配下に
application_env.php
といファイルがあり、

そこで、以下のような記述で設定が可能です。


$pattern ='/test[1-9]?/';
$match = array();
preg_match($pattern,$_SERVER["HTTP_HOST"],$match);
$test = $match[0];


$config['api_url'] = 'https://api-'.$test.'.●●●.net';
$config['pc_url'] = 'https://www-'.$test.'.●●●.net';
$config['sp_url'] = 'https://sp-'.$test.'.●●●.net';

設定例やURLは仮です。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4