From 8644699f4d2fce12a41289f9627bc45be9dd1965 Mon Sep 17 00:00:00 2001
From: Nguyễn Gia Phong
Date: Thu, 3 Dec 2020 09:32:13 +0700
Subject: [usth/ICT3.2] Develop web applications
---
usth/ICT3.2/prac/5/3.patch | 59 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
create mode 100644 usth/ICT3.2/prac/5/3.patch
(limited to 'usth/ICT3.2/prac/5/3.patch')
diff --git a/usth/ICT3.2/prac/5/3.patch b/usth/ICT3.2/prac/5/3.patch
new file mode 100644
index 0000000..98081e2
--- /dev/null
+++ b/usth/ICT3.2/prac/5/3.patch
@@ -0,0 +1,59 @@
+From ede9ffb8df2b225fb2deaea958f9cc126f3352b6 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?=
+Date: Sun, 11 Oct 2020 21:37:18 +0700
+Subject: [PATCH] Implement a simple RESTful API
+
+---
+ app/Config/Routes.php | 2 +-
+ app/Controllers/Home.php | 21 ++++++++++++++++-----
+ 2 files changed, 17 insertions(+), 6 deletions(-)
+
+diff --git a/app/Config/Routes.php b/app/Config/Routes.php
+index 56839ca..312d31e 100644
+--- a/app/Config/Routes.php
++++ b/app/Config/Routes.php
+@@ -30,7 +30,7 @@ $routes->setAutoRoute(true);
+
+ // We get a performance increase by specifying the default
+ // route since we don't have to scan directories.
+-$routes->get('/', 'Home::index');
++$routes->get('/(:any)', 'Home::index/$1');
+
+ /**
+ * --------------------------------------------------------------------
+diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php
+index 8798cdd..3c80328 100644
+--- a/app/Controllers/Home.php
++++ b/app/Controllers/Home.php
+@@ -1,12 +1,23 @@
+ /user
', '/user/{userId}/post
',
++ '/post
', '/post/{postId}/comment
'];
++
++ public function index($uri)
+ {
+- return view('welcome_message');
++ if (!file_exists($file = data($uri))) {
++ echo "Supported URIs:
\n";
++ return join("\n", $this->supported);
++ }
++ $this->response->setHeader('Access-Control-Allow-Origin', '*');
++ $this->response->setContentType('application/json');
++ readfile($file);
+ }
+-
+- //--------------------------------------------------------------------
+-
+ }
+--
+2.28.0
+
--
cgit 1.4.1