FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
react-tutorial/server.py at master · iWebHome/react-tutorial · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Jul 11, 2025. It is now read-only.
iWebHome
/
react-tutorial
Public archive
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.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (28 loc) · 1.43 KB
Breadcrumbs
react-tutorial
/
server.py
Copy path
File metadata and controls
36 lines (28 loc) · 1.43 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
# 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.
import
json
import
os
import
time
from
flask
import
Flask
,
Response
,
request
app
=
Flask
(
__name__
,
static_url_path
=
''
,
static_folder
=
'public'
)
app
.
add_url_rule
(
'/'
,
'root'
,
lambda
:
app
.
send_static_file
(
'index.html'
))
@
app
.
route
(
'/api/comments'
,
methods
=
[
'GET'
,
'POST'
])
def
comments_handler
():
with
open
(
'comments.json'
,
'r'
)
as
file
:
comments
=
json
.
loads
(
file
.
read
())
if
request
.
method
==
'POST'
:
newComment
=
request
.
form
.
to_dict
()
newComment
[
'id'
]
=
int
(
time
.
time
()
*
1000
)
comments
.
append
(
newComment
)
with
open
(
'comments.json'
,
'w'
)
as
file
:
file
.
write
(
json
.
dumps
(
comments
,
indent
=
4
,
separators
=
(
','
,
': '
)))
return
Response
(
json
.
dumps
(
comments
),
mimetype
=
'application/json'
,
headers
=
{
'Cache-Control'
:
'no-cache'
})
if
__name__
==
'__main__'
:
app
.
run
(
port
=
int
(
os
.
environ
.
get
(
"PORT"
,
3000
)))
Back
|
FazBrowse Home
|
New Git URL