File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ header ('Content-Type: application/json ' );
3+
4+ $ method = $ _SERVER ['REQUEST_METHOD ' ];
5+ $ path = parse_url ($ _SERVER ['REQUEST_URI ' ], PHP_URL_PATH );
6+
7+ // Strip /api/v1 prefix
8+ $ path = preg_replace ('#^/api/v1# ' , '' , $ path );
9+
10+ // Only allow POST for certain endpoints, GET for health
11+ if ($ method === 'POST ' ) {
12+ switch ($ path ) {
13+ case '/keys ' :
14+ include __DIR__ . '/../keygen.php ' ;
15+ break ;
16+
17+ case '/encrypt ' :
18+ include __DIR__ . '/../encrypt.php ' ;
19+ break ;
20+
21+ case '/decrypt ' :
22+ include __DIR__ . '/../decrypt.php ' ;
23+ break ;
24+
25+ default :
26+ http_response_code (404 );
27+ echo json_encode (['error ' => 'Not Found ' ]);
28+ }
29+ } elseif ($ method === 'GET ' && $ path === '/health ' ) {
30+ echo json_encode (['status ' => 'ok ' ]);
31+ } else {
32+ http_response_code (405 );
33+ echo json_encode (['error ' => 'Method Not Allowed ' ]);
34+ }
You can’t perform that action at this time.
0 commit comments