Skip to content

Commit 67aca8b

Browse files
committed
router fixed with async
1 parent 4b71e29 commit 67aca8b

File tree

6 files changed

+93
-82
lines changed

6 files changed

+93
-82
lines changed

package-lock.json

Lines changed: 74 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"express": "^4.16.4",
2727
"helmet": "^3.16.0",
2828
"jsonwebtoken": "^8.5.1",
29-
"knex": "^0.16.3",
29+
"knex": "^0.16.5",
3030
"mocha": "^6.1.4",
3131
"morgan": "^1.9.1",
3232
"node-fetch": "^2.3.0",

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ module.exports = {
77
CLIENT_SECRET: process.env.CLIENT_SECRET,
88

99
CLIENT_ORIGIN: process.env.CLIENT_ORIGIN || 'http://localhost:3000',
10+
DB_URL: process.env.DB_URL || 'postgresql://tunechainer@localhost/saved_playlists'
1011

1112
};

src/playlists/playlist-router.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ const serializeSavedPlaylists = search => ({
1818
});
1919

2020
playlistRouter
21-
.get('/', (req, res, next) => {
21+
.get('/', async (req, res, next) => {
2222
try {
23-
const list = PlaylistService.getSavedSearches(
23+
const list = await PlaylistService.getSavedSearches(
2424
req.app.get('db')
2525
);
2626

2727
res.json(list)
28-
.next();
28+
.end();
2929

3030

3131
} catch (error){

src/playlists/playlist-service.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ const PlaylistService = {
77
return db
88
.select('*')
99

10-
.from('saved_searches');
10+
.from('saved_searches')
11+
.then((results) => results);
12+
13+
1114

1215
},
1316

src/server.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,29 @@
22

33
const express = require('express');
44
const app = require('./app');
5+
const knex = require('knex');
6+
const { PORT, DB_URL } = require('./config');
57

68

79

810
const cors = require('cors');
911
const {CLIENT_ORIGIN} = require('./config');
1012

11-
const PORT = process.env.PORT || 8000;
13+
// const PORT = process.env.PORT || 8000;
14+
15+
const db = knex ({
16+
client: 'pg',
17+
connection: DB_URL
18+
});
1219

1320
app.use(
1421
cors({
1522
origin: CLIENT_ORIGIN
1623
})
1724
);
1825

26+
app.set('db', db);
27+
1928

2029

2130

0 commit comments

Comments
 (0)