Skip to content

Commit

Permalink
rollback : Vercel Serverless 구조 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
WoongyuChoi committed Dec 3, 2024
1 parent cc8c281 commit 23bea7b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 60 deletions.
92 changes: 51 additions & 41 deletions api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,54 @@
from handler.exception_handler import register_exception_handlers
from handler.logger import get_logger

cache = Cache()


def create_app():
app = Flask(__name__)
app.config.from_object(Config)

cache.init_app(app)
app.logger = get_logger(__name__)

register_exception_handlers(app)

@app.route("/")
def health_check():
app.logger.info("Health check called.")
status = {
"status": "UP",
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
"details": {"ecos_api": "UP" if check_ecos() else "DOWN"},
}
return jsonify(status), 200

@app.route("/favicon.<ext>")
def favicon(ext):
app.logger.debug(f"Favicon request received with extension: {ext}")
return "", 204, {"Content-Type": "image/x-icon"}

@app.route("/api/exchange-rate", methods=["GET"])
@cache.cached(query_string=True)
def get_exchange_rate():
start_date = request.args.get("start_date")
end_date = request.args.get("end_date")
item_code = request.args.get("item_code")

data = fetch_exchange_rate(
start_date=start_date, end_date=end_date, item_code=item_code
)
app.logger.info("Exchange rate data fetched successfully.")
return jsonify(data), 200

return app
app = Flask(__name__)
app.config.from_object(Config)

cache = Cache(app)
logger = get_logger(__name__)

register_exception_handlers(app)


@app.route("/")
def health_check():
app.logger.info("Health check called.")
status = {
"status": "UP",
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
"details": {"ecos_api": "UP" if check_ecos() else "DOWN"},
}
return jsonify(status), 200


@app.route("/favicon.<ext>")
def favicon(ext):
app.logger.debug(f"Favicon request received with extension: {ext}")
return "", 204, {"Content-Type": "image/x-icon"}


@app.route("/api/exchange-rate", methods=["GET"])
@cache.cached(query_string=True)
def get_exchange_rate():
start_date = request.args.get("start_date")
end_date = request.args.get("end_date")
item_code = request.args.get("item_code")

data = fetch_exchange_rate(
start_date=start_date, end_date=end_date, item_code=item_code
)
app.logger.info("Exchange rate data fetched successfully.")
return jsonify(data), 200


def handler(event, context):
from werkzeug.wrappers import Request, Response

request = Request(event)
response = Response.from_app(app, request.environ)

return {
"statusCode": response.status_code,
"headers": dict(response.headers),
"body": response.get_data(as_text=True),
}
17 changes: 1 addition & 16 deletions index.py
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
from api.server import create_app

app = create_app()


def handler(event, context):
from werkzeug.wrappers import Request, Response

request = Request(event)
response = Response.from_app(app, request.environ)

return {
"statusCode": response.status_code,
"headers": dict(response.headers),
"body": response.get_data(as_text=True),
}
from api.server import app
4 changes: 1 addition & 3 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from api.server import create_app

app = create_app()
from api.server import app

if __name__ == "__main__":
app.run(debug=True, port=5000)

0 comments on commit 23bea7b

Please sign in to comment.