Browse Source

Change GET request to server ipaddr

Carlos Hernandez 2 years ago
parent
commit
a555df819a

+ 2
- 0
.gitignore View File

@@ -1,3 +1,5 @@
1
+.vscode
2
+
1 3
 # Byte-compiled / optimized / DLL files
2 4
 __pycache__/
3 5
 *.py[cod]

+ 2
- 0
Files-API/MANIFEST.in View File

@@ -0,0 +1,2 @@
1
+graft articles_api/articles_files
2
+global-exclude *.pyc

+ 30
- 0
Files-API/articles_api/__init__.py View File

@@ -0,0 +1,30 @@
1
+import os
2
+
3
+from flask import Flask
4
+
5
+
6
+def create_app(test_config=None):
7
+    # create and configure the app
8
+    app = Flask(__name__)
9
+    app.config.from_mapping(
10
+        SECRET_KEY='dev')
11
+
12
+    if test_config is None:
13
+        # load the instance config, if it exists, when not testing
14
+        app.config.from_pyfile('config.py', silent=True)
15
+    else:
16
+        # load the test config if passed in
17
+        app.config.from_mapping(test_config)
18
+
19
+    # ensure the instance folder exists
20
+    try:
21
+        os.makedirs(app.instance_path)
22
+    except OSError:
23
+        pass
24
+
25
+    from articles_api.articles.articles import articles_api_bp
26
+
27
+    app.register_blueprint(articles_api_bp)
28
+    app.add_url_rule('/', endpoint="index")
29
+
30
+    return app

+ 29
- 0
Files-API/articles_api/articles/articles.py View File

@@ -0,0 +1,29 @@
1
+import os
2
+from flask import send_from_directory, jsonify, Blueprint, current_app
3
+from flask_cors import CORS, cross_origin
4
+
5
+
6
+articles_api_bp = Blueprint(
7
+    "articles", __name__, template_folder="templates")
8
+
9
+cors = CORS(articles_api_bp, resources={r"/articles": {"origins": "http://localhost:5500"}})
10
+
11
+
12
+@articles_api_bp.route("/<path:article>")
13
+@cross_origin(origin="localhost", headers=["Content-Type", "Authorization"])
14
+def send_text_file(article):
15
+    return send_from_directory(directory="articles_files", path=article)
16
+
17
+
18
+@articles_api_bp.route('/')
19
+@cross_origin(origin="localhost", headers=["Content-Type", "Authorization"])
20
+def index():
21
+    # List files in articles directory
22
+    files = list()
23
+    for filename in os.listdir(os.path.join(
24
+            current_app.root_path, "articles_files")):
25
+        path = os.path.join(os.path.join(
26
+            current_app.root_path, "articles_files"), filename)
27
+        if os.path.isfile(path):
28
+            files.append(filename)
29
+    return jsonify(files)

Files-API/articles/article_1.txt → Files-API/articles_api/articles_files/article_1.txt View File


Files-API/articles/article_2.txt → Files-API/articles_api/articles_files/article_2.txt View File


Files-API/articles/article_3.txt → Files-API/articles_api/articles_files/article_3.txt View File


+ 0
- 32
Files-API/files_api.py View File

@@ -1,32 +0,0 @@
1
-import os
2
-from flask import Flask, send_from_directory, jsonify
3
-from flask_cors import CORS, cross_origin
4
-
5
-
6
-app = Flask(__name__, static_url_path='')
7
-app.config["SECRET_KEY"] = "f82abccd93a28b6cdda4525c9afa7a30"
8
-app.config["CORS_HEADERS"] = "Content-Type"
9
-
10
-cors = CORS(app, resources={r"/articles": {"origins": "http://localhost:5500"}})
11
-
12
-
13
-@app.route("/articles/<path:article>")
14
-@cross_origin(origin="localhost", headers=["Content-Type", "Authorization"])
15
-def send_text_file(article):
16
-    return send_from_directory(directory="articles", path=article)
17
-
18
-
19
-@app.route("/articles")
20
-@cross_origin(origin="localhost", headers=["Content-Type", "Authorization"])
21
-def list_files():
22
-    files = list()
23
-    for filename in os.listdir("articles"):
24
-        path = os.path.join("articles", filename)
25
-        if os.path.isfile(path):
26
-            files.append(filename)
27
-    return jsonify(files)
28
-
29
-
30
-if __name__ == "__main__":
31
-    app.run()
32
-

+ 1
- 0
Files-API/requirements.txt View File

@@ -1,3 +1,4 @@
1
+-e git+https://git.ccom.uprrp.edu/ccorrada/CarDieAleCa.git@5055e56314e136e6abfc24a48da9767b89da8ad8#egg=articles_api&subdirectory=Files-API
1 2
 backcall==0.2.0
2 3
 click==8.0.3
3 4
 decorator==5.1.0

+ 5
- 0
Files-API/run.sh View File

@@ -0,0 +1,5 @@
1
+#!/bin/sh
2
+
3
+export FLASK_APP=articles_api
4
+export FLASK_ENV=development
5
+flask run

+ 14
- 0
Files-API/setup.py View File

@@ -0,0 +1,14 @@
1
+from setuptools import find_packages, setup
2
+
3
+setup(
4
+    name="articles_api",
5
+    version="1.0.0",
6
+    packages=["articles_api",
7
+              "articles_api.articles"],
8
+    include_package_data=True,
9
+    zip_safe=False,
10
+    install_requires=[
11
+        "flask",
12
+        "flask_cors"
13
+    ]
14
+)

+ 2
- 2
app_template/www/fetch_articles.js View File

@@ -1,10 +1,10 @@
1 1
 var articles;
2
-axios.get(`http://localhost:5000/articles`)
2
+axios.get("136.145.231.32:8080")
3 3
     .then(response => {
4 4
         articles = response.data;
5 5
         for (let i = 0; i < articles.length; i++) {
6 6
             let element = articles[i];
7
-            axios.get(`http://localhost:5000/articles/${element}`)
7
+            axios.get(`136.145.231.32:8080/${element}`)
8 8
                 .then(response => {
9 9
                     let articlesHeading = document.querySelector("#articles-heading").parentElement;
10 10
                     let articleButton = document.createElement("button");