Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ZRoom_App
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SCCA
ZRoom_App
Commits
c83be7f5
Commit
c83be7f5
authored
4 years ago
by
CemAdg
Browse files
Options
Downloads
Patches
Plain Diff
app.py flask app created
parent
d0a42c2e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backend/app.py
+88
-0
88 additions, 0 deletions
backend/app.py
with
88 additions
and
0 deletions
backend/app.py
+
88
−
0
View file @
c83be7f5
#first app
import
os
import
json
from
flask
import
Flask
,
request
,
jsonify
,
abort
from
flask_cors
import
CORS
def
create_app
(
test_config
=
None
):
app
=
Flask
(
__name__
)
CORS
(
app
)
"""
CORS Headers
after_request decorator to set Access-Control-Allow
"""
@app.after_request
def
after_request
(
response
):
response
.
headers
.
add
(
'
Access-Control-Allow-Headers
'
,
'
Content-Type,Authorization,true
'
)
response
.
headers
.
add
(
'
Access-Control-Allow-Methods
'
,
'
GET,POST,PATCH,DELETE,OPTIONS
'
)
return
response
"""
Check if app is running
"""
@app.route
(
'
/
'
,
methods
=
[
'
POST
'
,
'
GET
'
])
def
health
():
return
jsonify
(
"
Healthy
"
)
"""
GET /lamp/<int:lamp_id>/activate
"""
@app.route
(
'
/lamp/<int:lamp_id>/activate
'
,
methods
=
[
'
GET
'
])
def
activate_lamp
(
lamp_id
):
try
:
# activate GPIO pins der Leuchte lamp_id
if
lamp_id
==
1
:
return
jsonify
({
'
lamp_id
'
:
lamp_id
,
'
success
'
:
True
})
except
BaseException
:
abort
(
422
)
'''
error handlers for aborts
'''
@app.errorhandler
(
400
)
def
bad_request
(
error
):
return
jsonify
({
"
success
"
:
False
,
"
error
"
:
400
,
"
message
"
:
"
bad request
"
}),
400
@app.errorhandler
(
404
)
def
not_found
(
error
):
return
jsonify
({
"
success
"
:
False
,
"
error
"
:
404
,
"
message
"
:
"
resource not found
"
}),
404
@app.errorhandler
(
422
)
def
unprocessable
(
error
):
return
jsonify
({
"
success
"
:
False
,
"
error
"
:
422
,
"
message
"
:
"
unprocessable
"
}),
422
return
app
app
=
create_app
()
if
__name__
==
'
__main__
'
:
app
.
run
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment