feat: made server requests work
This commit is contained in:
parent
5ba56f5249
commit
6b9bd43e03
File diff suppressed because one or more lines are too long
|
@ -25,6 +25,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bufferutil": "4.0.3",
|
"bufferutil": "4.0.3",
|
||||||
"cookie-parser": "1.4.5",
|
"cookie-parser": "1.4.5",
|
||||||
|
"cors": "2.8.5",
|
||||||
"debug": "2.6.9",
|
"debug": "2.6.9",
|
||||||
"deemix": "3.0.3",
|
"deemix": "3.0.3",
|
||||||
"deezer-js": "^1.0.0",
|
"deezer-js": "^1.0.0",
|
||||||
|
@ -42,6 +43,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nuxtjs/eslint-config": "6.0.0",
|
"@nuxtjs/eslint-config": "6.0.0",
|
||||||
"@types/cookie-parser": "1.4.2",
|
"@types/cookie-parser": "1.4.2",
|
||||||
|
"@types/cors": "2.8.12",
|
||||||
"@types/debug": "4.1.5",
|
"@types/debug": "4.1.5",
|
||||||
"@types/express": "4.17.11",
|
"@types/express": "4.17.11",
|
||||||
"@types/express-session": "^1.17.3",
|
"@types/express-session": "^1.17.3",
|
||||||
|
|
|
@ -29,7 +29,7 @@ const DEEMIX_HOST = process.env.DEEMIX_HOST ?? argv.host
|
||||||
|
|
||||||
const debug = initDebug('deemix-gui:server')
|
const debug = initDebug('deemix-gui:server')
|
||||||
export const wss = new WsServer({ noServer: true })
|
export const wss = new WsServer({ noServer: true })
|
||||||
const app: Application = express()
|
export const app: Application = express()
|
||||||
const server = http.createServer(app)
|
const server = http.createServer(app)
|
||||||
|
|
||||||
/* === Middlewares === */
|
/* === Middlewares === */
|
||||||
|
|
|
@ -35,7 +35,7 @@ async function startApp() {
|
||||||
render: h => h(App)
|
render: h => h(App)
|
||||||
}).$mount('#app')
|
}).$mount('#app')
|
||||||
|
|
||||||
const connectResponse = await (await fetch(`${SERVER_ENDPOINT}/connect`)).json()
|
const connectResponse = await (await fetch(`${SERVER_ENDPOINT}/connect`, { credentials: 'include' })).json()
|
||||||
if (!connectResponse.deezerAvailable) document.getElementById('deezer_not_available').classList.remove('hide')
|
if (!connectResponse.deezerAvailable) document.getElementById('deezer_not_available').classList.remove('hide')
|
||||||
|
|
||||||
store.dispatch('setAppInfo', connectResponse.update).catch(console.error)
|
store.dispatch('setAppInfo', connectResponse.update).catch(console.error)
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
export const SERVER_ENDPOINT = 'http://localhost:6595'
|
export const SERVER_ENDPOINT = 'http://localhost:6595'
|
||||||
export const SERVER_HOST = 'localhost:6595'
|
export const SERVER_HOST = 'localhost:6595'
|
||||||
|
|
||||||
|
const commonOptions = {
|
||||||
|
credentials: 'include'
|
||||||
|
}
|
||||||
|
|
||||||
export function fetchData(key, data = {}, method = 'GET') {
|
export function fetchData(key, data = {}, method = 'GET') {
|
||||||
const url = new URL(`${SERVER_ENDPOINT}/api/${key}`)
|
const url = new URL(`${SERVER_ENDPOINT}/api/${key}`)
|
||||||
|
|
||||||
|
@ -9,7 +13,7 @@ export function fetchData(key, data = {}, method = 'GET') {
|
||||||
url.searchParams.append(key, data[key])
|
url.searchParams.append(key, data[key])
|
||||||
})
|
})
|
||||||
|
|
||||||
return fetch(url.href, { method })
|
return fetch(url.href, { ...commonOptions, method })
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('There has been a problem with your fetch operation:', error)
|
console.error('There has been a problem with your fetch operation:', error)
|
||||||
|
@ -33,6 +37,7 @@ export const postToServer = (endpoint, data) => {
|
||||||
const url = new URL(`${SERVER_ENDPOINT}/api/${endpoint}`)
|
const url = new URL(`${SERVER_ENDPOINT}/api/${endpoint}`)
|
||||||
|
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
|
...commonOptions,
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
|
Loading…
Reference in New Issue