We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 558e0c7 commit d62a968Copy full SHA for d62a968
server.php
@@ -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
19
+ default:
20
+ return false;
21
+}
0 commit comments