novar

node v4.9.1
version: 0.0.1
endpointsharetweet
Novar
class Novar { constructor() { this.settings = {}; } isClient() { throw new Error('isClient method not implemented'); } isServer() { throw new Error('isServer method not implemented'); } isDevelopment() { throw new Error('isDevelopment method not implemented'); } absoluteUrl() { throw new Error('absoluteUrl method not implemented'); } } exports.Novar = Novar; exports
Novar Accounts Module
Novar.prototype.Accounts = { LOCAL_STORAGE_LOGIN_TOKEN_KEY: 'Novar.loginToken', LOCAL_STORAGE_LOGIN_TOKEN_EXPIRES_KEY: 'Novar.loginTokenExpires', COOKIES_LOGIN_TOKEN_KEY: 'novar_login_token', }
Novar ApolloClient Module
// https://github.com/apollographql/meteor-integration/commit/9c0165bee4ede2c1a1b6a732235a1ebc0b02e20f const { ApolloClient, createNetworkInterface, createBatchingNetworkInterface } = require('apollo-client'); require('isomorphic-fetch'); Novar.prototype.ApolloClient = { createApolloNetworkInterface(givenConfig = {}) { const config = { ...defaultNetworkInterfaceConfig, ...givenConfig }; // absoluteUrl adds a '/', so let's remove it first let path = config.path; if (path[0] === '/') { path = path.slice(1); } const uri = this.absoluteUrl( path, { rootUrl: this.Settings.getSetting('developmentServerIp', this.absoluteUrl()) }, ); // allow the use of a batching network interface; // if the options.batchingInterface is not specified, // fallback to the standard network interface const interfaceToUse = config.batchingInterface ? createBatchingNetworkInterface : createNetworkInterface; // default interface options const interfaceOptions = { uri, opts: { credentials: 'same-origin', // http://dev.apollodata.com/react/auth.html#Cookie }, }; // if a BatchingNetworkInterface is used with a correct batch interval, add it to the options if (config.batchingInterface && config.batchInterval) { interfaceOptions.batchInterval = config.batchInterval; } // if 'fetch' has been configured to be called with specific opts, add it to the options if (Object.keys(config.opts).length > 0) { interfaceOptions.opts = config.opts; } const networkInterface = interfaceToUse(interfaceOptions); networkInterface.use([{ applyMiddleware(request, next) { const currentUserToken = Novar.isClient() ? global.localStorage[config.loginTokenKey] : config.loginToken; if (!currentUserToken) { next(); return; } if (!request.options.headers) { request.options.headers = new Headers(); } request.options.headers.Authorization = currentUserToken; next(); }, }]); return networkInterface; } } // import { Novar } from './novar.js'; // import { Settings } from './settings.js'; // const ApolloClient = {}; // const defaultNetworkInterfaceConfig = { // path: '/graphql', // default graphql server endpoint // opts: {}, // additional fetch options like `credentials` or `headers` // batchingInterface: false, // use a BatchingNetworkInterface by default instead of a NetworkInterface // batchInterval: 10, // default batch interval // }; // const createApolloNetworkInterface = (givenConfig = {}) => { // const config = { ...defaultNetworkInterfaceConfig, ...givenConfig }; // // absoluteUrl adds a '/', so let's remove it first // let path = config.path; // if (path[0] === '/') { // path = path.slice(1); // } // const uri = Novar.absoluteUrl( // path, // { rootUrl: Settings.getSetting('developmentServerIp', Novar.absoluteUrl()) }, // ); // // allow the use of a batching network interface; if the options.batchingInterface is not specified, fallback to the standard network interface // const interfaceToUse = config.batchingInterface ? createBatchingNetworkInterface : createNetworkInterface; // // default interface options // const interfaceOptions = { // uri, // opts: { // credentials: 'same-origin', // http://dev.apollodata.com/react/auth.html#Cookie // }, // }; // // if a BatchingNetworkInterface is used with a correct batch interval, add it to the options // if (config.batchingInterface && config.batchInterval) { // interfaceOptions.batchInterval = config.batchInterval; // } // // if 'fetch' has been configured to be called with specific opts, add it to the options // if (Object.keys(config.opts).length > 0) { // interfaceOptions.opts = config.opts; // } // const networkInterface = interfaceToUse(interfaceOptions); // networkInterface.use([{ // applyMiddleware(request, next) { // const currentUserToken = Novar.isClient() ? global.localStorage[config.loginTokenKey] : config.loginToken; // if (!currentUserToken) { // next(); // return; // } // if (!request.options.headers) { // request.options.headers = new Headers(); // } // request.options.headers.Authorization = currentUserToken; // next(); // }, // }]); // return networkInterface; // }; // const createApolloClientConfig = networkInterfaceConfig => ({ // ssrMode: Novar.isServer(), // networkInterface: createApolloNetworkInterface(networkInterfaceConfig), // queryDeduplication: true, // http://dev.apollodata.com/core/network.html#query-deduplication // // Default to using Mongo _id, must use _id for queries. // dataIdFromObject(result) { // if (result._id && result.__typename) { // const dataId = result.__typename + result._id; // return dataId; // } // return null; // }, // }); // ApolloClient.createApolloClient = options => new Client(createApolloClientConfig(options)); // export { ApolloClient as default, ApolloClient };
class NovarServer extends Novar { isClient() { return false; } isServer() { return true; } } const novarServer = new NovarServer();
novarServer.Accounts
Loading…

no comments

    sign in to comment