-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5013daf
commit 992c08b
Showing
9 changed files
with
195 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import feathers from '@feathersjs/feathers' | ||
import socketio from '@feathersjs/socketio-client' | ||
import io from 'socket.io-client' | ||
import authentication from '@feathersjs/authentication-client' | ||
import urlHelper from '~/helpers/urls' | ||
import Cookie from 'cookie-universal' | ||
|
||
const authKey = 'feathers-jwt' | ||
let socket | ||
|
||
const getSocket = (app) => { | ||
if (socket) return socket | ||
|
||
const endpoint = urlHelper.buildEndpointURL(app.$env.API_HOST, { port: app.$env.API_PORT }) | ||
if (process.env.ENV === 'production') { | ||
socket = socketio(io(endpoint), { timeout: 20000 }) | ||
if (process.server) { | ||
setTimeout(() => { | ||
// close server connection as content was delivered already after 30 seconds at latest | ||
try { | ||
socket.close() | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
}, 30000) | ||
} | ||
} else { | ||
socket = socketio(io(endpoint)) | ||
} | ||
|
||
return socket | ||
} | ||
|
||
let createApiClient = ({app, req, res}) => { | ||
const cookies = Cookie(req, res) | ||
const storageMapping = { | ||
getItem: (key) => { | ||
const res = cookies.get(key) | ||
// console.log(`## STORAGE: getItem(${key})`, res) | ||
return res | ||
}, | ||
setItem: (key, value, options) => { | ||
const res = cookies.set(key, value, options) | ||
// console.log(`## STORAGE: setItem(${key}, ${value}, ${options})`, res) | ||
return res | ||
}, | ||
removeItem: (key) => { | ||
const res = cookies.remove(key) | ||
// console.log(`## STORAGE: removeItem(${key})`, res) | ||
return res | ||
}, | ||
clear: () => { | ||
const res = cookies.removeAll() | ||
if (process.env.NODE_ENV === 'development') { | ||
console.log(`## STORAGE: clear()`, res) | ||
} | ||
return res | ||
} | ||
} | ||
|
||
let api = feathers() | ||
.configure(getSocket(app)) | ||
.configure(authentication({ | ||
storage: storageMapping, | ||
storageKey: authKey, | ||
cookie: authKey | ||
})) | ||
|
||
return api | ||
} | ||
|
||
export default createApiClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import createApiClient from '../helpers/createApiClient' | ||
|
||
const requireModule = require.context( | ||
// The relative path holding the service modules | ||
'../store/services', | ||
// Whether to look in subfolders | ||
false, | ||
// Only include .js files (prevents duplicate imports) | ||
/.js$/ | ||
) | ||
|
||
export default async ({app, store, req, res}) => { | ||
const feathersClient = createApiClient({app, req, res}) | ||
|
||
const servicePlugins = requireModule.keys().map(modulePath => requireModule(modulePath).default(feathersClient)) | ||
servicePlugins.forEach((servicePlugin) => { | ||
servicePlugin(store) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { initAuth } from 'feathers-vuex' | ||
|
||
export const actions = { | ||
nuxtServerInit ({ commit, dispatch }, { req }) { | ||
return initAuth({ | ||
commit, | ||
dispatch, | ||
req, | ||
moduleName: 'auth', | ||
cookieName: 'feathers-jwt' | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import feathersVuex from 'feathers-vuex' | ||
|
||
let servicePlugin = (feathersClient) => { | ||
const { service } = feathersVuex(feathersClient, { idField: '_id' }) | ||
const servicePath = 'users' | ||
const servicePlugin = service(servicePath, { | ||
namespace: 'feathers-vuex-users' | ||
}) | ||
return servicePlugin | ||
} | ||
export default servicePlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import feathersVuex from 'feathers-vuex' | ||
|
||
let servicePlugin = (feathersClient) => { | ||
const { service } = feathersVuex(feathersClient, { idField: '_id' }) | ||
const servicePath = 'usersettings' | ||
const servicePlugin = service(servicePath, { | ||
namespace: 'feathers-vuex-usersettings' | ||
}) | ||
return servicePlugin | ||
} | ||
export default servicePlugin |
Oops, something went wrong.