Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function publishService (app, path) {
const service = app.service(path)
if (!service || (typeof service !== 'object')) return
if (service.remote) {
debug('Ignoring remote service publication on path ' + path + ' for app with uuid ' + app.uuid)
return
}
const serviceDescriptor = {
uuid: app.uuid,
path: stripSlashes(path),
events: service.distributedEvents || service._serviceEvents
}
// Skip internal services
if (isInternalService(app, serviceDescriptor)) {
debug('Ignoring local service on path ' + serviceDescriptor.path + ' for app with uuid ' + app.uuid)
return
}
// Register the responder to handle remote calls to the service
if (!service.responder) service.responder = new LocalService(Object.assign({ app }, serviceDescriptor))
// Publish new local service
app.servicePublisher.publish('service', serviceDescriptor)
debug('Published local service on path ' + serviceDescriptor.path + ' for app with uuid ' + app.uuid)
}
service (path, service) {
if (typeof service !== 'undefined') {
throw new Error('Registering a new service with `app.service(path, service)` is no longer supported. Use `app.use(path, service)` instead.');
}
const location = stripSlashes(path) || '/';
const current = this.services[location];
if (typeof current === 'undefined' && typeof this.defaultService === 'function') {
return this.use(location, this.defaultService(location))
.service(location);
}
return current;
},
return (context: HookContext) => {
const { app, params, path, method, app: { authentication: service } } = context;
if (stripSlashes(service.options.path) === path && method === 'create') {
return context;
}
return Promise.resolve(app.get('authentication')).then(authResult => {
if (authResult) {
context.params = Object.assign({}, authResult, params);
}
return context;
});
};
};
use (path, service, options = {}) {
if (typeof path !== 'string') {
throw new Error(`'${path}' is not a valid service path.`);
}
const location = stripSlashes(path) || '/';
const isSubApp = typeof service.service === 'function' && service.services;
const isService = this.methods.concat('setup').some(name => typeof service[name] === 'function');
if (isSubApp) {
const subApp = service;
Object.keys(subApp.services).forEach(subPath =>
this.use(`${location}/${subPath}`, subApp.service(subPath))
);
return this;
}
if (!isService) {
throw new Error(`Invalid service object passed for path \`${location}\``);
}
function parseRoute (path, methods, method, route) {
return {
method,
verb: route.verb,
uri: route.uri ? `/${path}/${stripSlashes(route.uri)}` : getDefaultUri(path, methods, method)
};
}
lookup (path: string): { [key: string]: string } {
if (!path) {
return null;
}
return this[ROUTER].lookup(stripSlashes('' + path) || '/');
}
});
constructor (settings) {
this.name = stripSlashes(settings.name);
this.options = settings.options;
this.connection = settings.connection;
this.base = `${settings.base}/${this.name}`;
}