This repository was archived by the owner on Dec 8, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed
Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ FROM alpine:latest
2+ LABEL maintainer="Sam Hoffman <sam@codewizardshq.com>"
3+
4+ RUN apk --update add --no-cache python3 bash curl binutils libc-dev python3-dev gcc
5+ RUN pip3 install -U pip
6+ RUN pip3 install flask flask-cors pyduktape gunicorn
7+
8+ RUN adduser -D -H webapp
9+ RUN mkdir -p "/var/www/flaskapp"
10+
11+ # default Flask port
12+ EXPOSE 5000/tcp
13+
14+ USER webapp
15+
16+ COPY "start.sh" "/tmp/start.sh"
17+ COPY "app.py" "/var/www/flaskapp/app.py"
18+
19+ ENTRYPOINT [ "/tmp/start.sh" ]
Original file line number Diff line number Diff line change 1+ import pyduktape
2+ from flask import Flask , jsonify , request
3+ from flask_cors import CORS
4+
5+ app = Flask (__name__ )
6+ CORS (app )
7+
8+
9+ @app .route ("/js/eval" , methods = ["POST" ])
10+ def js_eval ():
11+ """Eval some JavaScript using pyduktape"""
12+
13+ if not request .is_json :
14+ return jsonify (error = "payload must be JSON format" ), 400
15+
16+ data = request .get_json ()
17+
18+ try :
19+ code = data ["code" ]
20+ except KeyError :
21+ return jsonify (error = "missing 'code' parameter" ), 400
22+
23+ ctx = pyduktape .DuktapeContext ()
24+
25+ output = ""
26+ error = ""
27+
28+ code += ";output"
29+
30+ try :
31+ output = ctx .eval_js (code )
32+ except Exception as e :
33+ error = str (e )
34+
35+ return jsonify (output = output , error = error )
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+ set -e
3+ cd " /var/www/flaskapp/"
4+ gunicorn -b 0.0.0.0:5000 app:app
You can’t perform that action at this time.
0 commit comments