Skip to content

Commit

Permalink
exclude api from caching
Browse files Browse the repository at this point in the history
  • Loading branch information
teticio committed Aug 18, 2021
1 parent fbc7192 commit f47e636
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REACT_APP_API_URL='http://localhost:8000'
REACT_APP_API_URL='http://localhost:8000/api/v1'
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REACT_APP_API_URL='https://deej-ai.online'
REACT_APP_API_URL='https://deej-ai.online/api/v1'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You will also need to download the following files to the root directory:
* https://drive.google.com/file/d/16JKjDGW2BMP-0KKJLFvwRvJdKhwukBeB/view?usp=sharing
* https://drive.google.com/file/d/1LM1WW1GCGKeFD1AAHS8ijNwahqH4r4xV/view?usp=sharing

You should also set `REACT_APP_API_URL` to `'<Your external webpage URL>'` in `.env.production` to point to the external URL where you are hosting the web app.
You should also set `REACT_APP_API_URL` to `'<Your external webpage URL>/api/v1'` in `.env.production`s.

If you have `pipenv` and `yarn` already installed you can then type

Expand Down
26 changes: 13 additions & 13 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_db():
)


@app.get("/login")
@app.get("/api/v1/login")
async def spotify_login():
scope = "playlist-modify-public user-read-currently-playing"
url = "https://accounts.spotify.com/authorize?" + urllib.parse.urlencode(
Expand Down Expand Up @@ -94,7 +94,7 @@ async def spotify_callback(code: str):
return RedirectResponse(url=url)


@app.get("/refresh_token")
@app.get("/api/v1/refresh_token")
async def spotify_refresh_token(refresh_token: str):
data = {'refresh_token': refresh_token, 'grant_type': 'refresh_token'}
headers = {
Expand All @@ -117,19 +117,19 @@ async def spotify_refresh_token(refresh_token: str):
return json


@app.post("/search")
@app.post("/api/v1/search")
async def search_tracks(search: schemas.Search):
ids = await deejai.search(search.string, search.max_items)
return [{'track_id': id, 'track': deejai.get_tracks()[id]} for id in ids]


@app.post("/search_similar")
@app.post("/api/v1/search_similar")
async def search_similar_tracks(search: schemas.SearchSimilar):
ids = await deejai.get_similar_vec(search.url, search.max_items)
return [{'track_id': id, 'track': deejai.get_tracks()[id]} for id in ids]


@app.post("/playlist")
@app.post("/api/v1/playlist")
async def playlist(playlist: schemas.NewPlaylist):
ids = await deejai.playlist(playlist.track_ids, playlist.size,
playlist.creativity, playlist.noise)
Expand All @@ -139,7 +139,7 @@ async def playlist(playlist: schemas.NewPlaylist):
}


@app.post("/create_playlist")
@app.post("/api/v1/create_playlist")
def create_playlist(playlist: schemas.Playlist, db: Session = Depends(get_db)):
db_item = models.Playlist(**playlist.dict())
try:
Expand All @@ -160,14 +160,14 @@ def create_playlist(playlist: schemas.Playlist, db: Session = Depends(get_db)):
return db_item


@app.get("/read_playlist")
@app.get("/api/v1/read_playlist")
def get_playlist(id: int, db: Session = Depends(get_db)):
db_item = db.query(
models.Playlist).filter(models.Playlist.id == id).first()
return db_item


@app.post("/update_playlist_name")
@app.post("/api/v1/update_playlist_name")
def update_playlist_name(playlist: schemas.PlaylistName,
db: Session = Depends(get_db)):
db_item = db.query(
Expand All @@ -176,7 +176,7 @@ def update_playlist_name(playlist: schemas.PlaylistName,
db.commit()


@app.post("/update_playlist_rating")
@app.post("/api/v1/update_playlist_rating")
def update_playlist_rating(playlist: schemas.PlaylistRating,
db: Session = Depends(get_db)):
db_item = db.query(
Expand All @@ -188,7 +188,7 @@ def update_playlist_rating(playlist: schemas.PlaylistRating,
db.commit()


@app.post("/update_playlist_id")
@app.post("/api/v1/update_playlist_id")
def update_playlist_id(playlist: schemas.PlaylistId,
db: Session = Depends(get_db)):
db_item = db.query(
Expand All @@ -200,21 +200,21 @@ def update_playlist_id(playlist: schemas.PlaylistId,
db.commit()


@app.get("/latest_playlists")
@app.get("/api/v1/latest_playlists")
def get_latest_playlists(top_n: int, db: Session = Depends(get_db)):
db_items = db.query(models.Playlist).order_by(desc(
models.Playlist.created)).limit(top_n).all()
return db_items


@app.get("/top_playlists")
@app.get("/api/v1/top_playlists")
def get_top_playlists(top_n: int, db: Session = Depends(get_db)):
db_items = db.query(models.Playlist).order_by(
desc(models.Playlist.av_rating)).limit(top_n).all()
return db_items


@app.post("/search_playlists")
@app.post("/api/v1/search_playlists")
def search_playlists(search: schemas.SearchPlaylists,
db: Session = Depends(get_db)):
db_items = []
Expand Down
4 changes: 4 additions & 0 deletions src/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ registerRoute(
return false;
} // Return true to signal that we want to use the handler.

if (url.pathname.startsWith('/api')) {
return false;
}

return true;
},
createHandlerBoundToURL(process.env.PUBLIC_URL + '/index.html')
Expand Down

0 comments on commit f47e636

Please sign in to comment.