Skip to content

Commit d62a968

Browse files
committed
add initial version of the php server
1 parent 558e0c7 commit d62a968

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

server.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
$comments = file_get_contents('_comments.json');
3+
switch($_SERVER["REQUEST_URI"]) {
4+
case '/':
5+
echo file_get_contents('./public/index.html');
6+
break;
7+
case '/comments.json':
8+
if($_SERVER['REQUEST_METHOD'] === 'POST') {
9+
$commentsDecoded = json_decode($comments, true);
10+
$commentsDecoded[] = ['author' => $_POST['author'],
11+
'text' => $_POST['text']];
12+
13+
$comments = json_encode($commentsDecoded);
14+
file_put_contents('_comments.json', $comments);
15+
}
16+
header('Content-Type: application/json');
17+
echo $comments;
18+
break;
19+
default:
20+
return false;
21+
}

0 commit comments

Comments
 (0)