FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
react-tutorial/server.php at master · ssejava/react-tutorial · GitHub
ssejava
/
react-tutorial
Public
forked from
reactjs/react-tutorial
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
react-tutorial
/
server.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (48 loc) · 1.81 KB
Breadcrumbs
react-tutorial
/
server.php
Copy path
File metadata and controls
52 lines (48 loc) · 1.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* This file provided by Facebook is for non-commercial testing and evaluation
* purposes only. Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
$
scriptInvokedFromCli
=
isset
(
$
_SERVER
[
'
argv
'
][
0
]) &&
$
_SERVER
[
'
argv
'
][
0
] ===
'
server.php
'
;
if
(
$
scriptInvokedFromCli
) {
$
port
=
getenv
(
'
PORT
'
);
if
(
empty
(
$
port
)) {
$
port
=
"
3000
"
;
}
echo
'
starting server on port
'
.
$
port
.
PHP_EOL
;
exec
(
'
php -S localhost:
'
.
$
port
.
'
-t public server.php
'
);
}
else
{
return
routeRequest
();
}
function
routeRequest
()
{
$
comments
=
file_get_contents
(
'
comments.json
'
);
$
uri
=
$
_SERVER
[
'
REQUEST_URI
'
];
if
(
$
uri
==
'
/
'
) {
echo
file_get_contents
(
'
./public/index.html
'
);
}
elseif
(
preg_match
(
'
/\/api\/comments(\?.*)?/
'
,
$
uri
)) {
if
(
$
_SERVER
[
'
REQUEST_METHOD
'
] ===
'
POST
'
) {
$
commentsDecoded
=
json_decode
(
$
comments
,
true
);
$
commentsDecoded
[] = [
'
id
'
=>
round
(
microtime
(
true
) *
1000
),
'
author
'
=>
$
_POST
[
'
author
'
],
'
text
'
=>
$
_POST
[
'
text
'
]
];
$
comments
=
json_encode
(
$
commentsDecoded
,
JSON_PRETTY_PRINT
);
file_put_contents
(
'
comments.json
'
,
$
comments
);
}
header
(
'
Content-Type: application/json
'
);
header
(
'
Cache-Control: no-cache
'
);
echo
$
comments
;
}
else
{
return
false
;
}
}
Back
|
FazBrowse Home
|
New Git URL