Skip to content

Commit

Permalink
Merge pull request #8 from rafaVls/hamburger-refactor
Browse files Browse the repository at this point in the history
Hamburger refactor
  • Loading branch information
rafaVls authored Jan 28, 2022
2 parents 664339e + debf4d1 commit f3566fa
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 12 deletions.
3 changes: 0 additions & 3 deletions backend/.example.env

This file was deleted.

1 change: 0 additions & 1 deletion backend/.example.flaskenv
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
FLASK_APP=weatherly
FLASK_ENV=development
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ charset-normalizer==2.0.7
click==8.0.3
coverage==6.1.2
Flask==2.0.2
Flask-Cors==3.0.10
idna==3.3
iniconfig==1.1.1
itsdangerous==2.0.1
Expand Down
6 changes: 6 additions & 0 deletions backend/start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from weatherly import create_app

app = create_app('flask_production.cfg')

if __name__ == '__main__':
app.run();
2 changes: 2 additions & 0 deletions backend/weatherly/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from flask import Flask
from flask_cors import CORS
from . import forecast, geocoding, reverse_geocoding

def create_app(config_filename="flask.cfg"):
app = Flask(__name__, instance_relative_config=True)
CORS(app)

app.config.from_pyfile(config_filename)
app.register_blueprint(forecast.bp)
Expand Down
4 changes: 2 additions & 2 deletions backend/weatherly/forecast.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from os import environ
from flask import Blueprint, request
from flask import Blueprint, request, current_app

from .Param import Param
from ._utils import multithread_request, fetch_api
Expand Down Expand Up @@ -27,7 +27,7 @@ def get_forecast():
"lat": latitude.value,
"lon": longitude.value,
"exclude": "minutely,alerts",
"appid": environ.get("ONECALL_API_KEY")
"appid": current_app.config["ONECALL_API_KEY"]
}

data_metric, data_imperial = multithread_request(
Expand Down
4 changes: 2 additions & 2 deletions backend/weatherly/geocoding.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from os import environ
from flask import Blueprint, request
from flask import Blueprint, request, current_app

from .Param import Param
from ._utils import fetch_api
Expand All @@ -21,7 +21,7 @@ def get_coordinates():
url = "https://maps.googleapis.com/maps/api/geocode/json"
payload = {
"address": address.value,
"key": environ.get("GEOCODING_API_KEY")
"key": current_app.config["GEOCODING_API_KEY"]
}

data = fetch_api(payload, url)
Expand Down
4 changes: 2 additions & 2 deletions backend/weatherly/reverse_geocoding.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from os import environ
from flask import Blueprint, request
from flask import Blueprint, request, current_app

from .Param import Param
from ._utils import fetch_api
Expand All @@ -24,7 +24,7 @@ def get_reverse_geocode():
payload = {
"latlng": f"{latitude.value},{longitude.value}",
"result_type": "political",
"key": environ.get("REVERSE_GEOCODING_API_KEY")
"key": current_app.config["REVERSE_GEOCODING_API_KEY"]
}

data = fetch_api(payload, url)
Expand Down
13 changes: 13 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react-dom": "^17.0.2"
},
"devDependencies": {
"@types/node": "^17.0.13",
"@types/react": "^17.0.35",
"@types/react-dom": "^17.0.11",
"@vitejs/plugin-react": "^1.0.9",
Expand Down
5 changes: 3 additions & 2 deletions client/src/context/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Props = {

function GlobalProvider({ children }: Props) {
const [state, dispatch] = useReducer(AppReducer, initialState);
const API_URL = import.meta.env.VITE_API_URL;

function setCoordinates(latitude: number, longitude: number): void {
dispatch({
Expand All @@ -34,7 +35,7 @@ function GlobalProvider({ children }: Props) {
const lat = position.lat;
const lon = position.lng;

const url = `//localhost:5000/forecast?lat=${lat}&lon=${lon}`;
const url = `${API_URL}/forecast?lat=${lat}&lon=${lon}`;
const res = await fetch(url);
const { forecast_imperial, forecast_metric } = await res.json();

Expand All @@ -55,7 +56,7 @@ function GlobalProvider({ children }: Props) {

async function getGeocoding(address: string): Promise<void> {
try {
const url = `//localhost:5000/geocoding?address=${address}`;
const url = `${API_URL}/geocoding?address=${address}`;
const res = await fetch(url);
const { data } = await res.json();

Expand Down
9 changes: 9 additions & 0 deletions client/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_API_URL: string;
}

interface ImportMeta {
readonly env: ImportMetaEnv;
}

1 comment on commit f3566fa

@vercel
Copy link

@vercel vercel bot commented on f3566fa Jan 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.