Socket
Socket
Sign inDemoInstall

@wix/be-server

Package Overview
Dependencies
Maintainers
6
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wix/be-server - npm Package Compare versions

Comparing version 1.0.115 to 1.0.116

lib/server-launcher.js

10

index.d.ts

@@ -0,1 +1,3 @@

import {be} from '@wix/be-http-binding';
export function builder(): ServerBuilder;

@@ -6,3 +8,3 @@

export interface ServerBuilder {
withBindings(bindings: Binding[])
withBindings(bindings: be.HttpBinding)
withBindingsSource(bindingsSource: BindingsSource)

@@ -16,9 +18,7 @@ start(options: StartOptions): Promise<Server>

export interface Binding {
binding: HttpBinding
invoke: (request: any, options?: object) => any
export abstract class ServerLauncher {
public static embedded(require: () => void, options: StartOptions): Promise<Server>;
}
export interface BindingsSource {
}

@@ -25,0 +25,0 @@

const {serverBuilder} = require('./lib/server-builder');
const protoModulesBindings = require('./lib/proto-modules-bindings');
const serverLauncher = require('./lib/server-launcher');
module.exports = {
builder: serverBuilder,
fromProtoModules: protoModulesBindings
fromProtoModules: protoModulesBindings,
ServerLauncher: serverLauncher
};

@@ -45,9 +45,9 @@ const {create} = require('@wix/proto-packages');

route[httpMethod].forEach((path) => {
bindings.push({
binding: httpBinding.http(
bindings.push(
httpBinding.http(
httpBinding[httpMethod.toLowerCase()](path),
types.lookup(service, method.requestType),
types.lookup(service, method.responseType)),
invoke: implementationBindings[jsMethodName]
});
types.lookup(service, method.responseType)).bind(
implementationBindings[jsMethodName]),
);
});

@@ -54,0 +54,0 @@ });

@@ -8,6 +8,6 @@ const url = require('url');

bindings.forEach(({binding, invoke}) => {
bindings.forEach((binding) => {
binding.httpRoutes().forEach(({method, path}) => {
const httpMethodLower = method.toLowerCase();
if (!routes[httpMethodLower]) {

@@ -20,3 +20,3 @@ routes[httpMethodLower] = [];

method,
invoke: binding.createInvoke(invoke)
invoke: binding.invoke
});

@@ -23,0 +23,0 @@ })

@@ -12,6 +12,5 @@ const routes = require('./routes');

const givenBinding = http(get('/echo'), echoMessage, echoMessage);
const givenRoutes = routes([{
binding: givenBinding,
invoke: (message) => message
}]);
const givenRoutes = routes([
givenBinding.bind((message) => message)
]);

@@ -36,6 +35,5 @@ const {request, invoke} = givenRoutes.resolve('GET', '/echo?message=Hello');

const givenRoutes = routes([{
binding: givenBinding,
invoke: (message) => message
}]);
const givenRoutes = routes([
givenBinding.bind((message) => message)
]);

@@ -48,3 +46,3 @@ const {request, invoke} = givenRoutes.resolve('GET', '/api/path-1?valueFromQuery=query-1');

});
expect(invoke).to.exist;

@@ -59,6 +57,4 @@ expect(await invoke(request)).to.deep.equal(request);

const givenRoutes = routes([{
binding: givenBinding,
invoke: (message) => message
}]);
const givenRoutes = routes([
givenBinding.bind((message) => message)]);

@@ -65,0 +61,0 @@ const {request, invoke} = givenRoutes.resolve('GET', '/api/path-1?test.arr=arr-1&test.arr=arr-2&test.bool=true&num=10');

@@ -9,3 +9,5 @@ const startServer = require('./server');

return {
withBindings(bindings) {
withBindings() {
const bindings = Array.prototype.slice.call(arguments);
return serverBuilder({

@@ -23,2 +25,6 @@ ...context,

async start(options) {
if (!options && process.env.BE_SERVER_START_OPTIONS) {
options = JSON.parse(process.env.BE_SERVER_START_OPTIONS);
}
const sourcedBindings = context.bindingsSource ? await context.bindingsSource.bindings() : [];

@@ -25,0 +31,0 @@ const dynamicBindings = context.bindings || [];

const http = require('http');
const routes = require('./routes');
const launcher = require('./server-launcher');
const debug = require('debug')('be-server');
module.exports = function start(options) {
if (!options.port) {
throw new Error('Port has to be defined');
}
debug(`Server starting at ${options.port}`);
const methodRoutes = routes(options.bindings);
const server = http.createServer(async(req, res) => {
if (req.method === 'OPTIONS' && req.url === '/') {
res.statusCode = 204;
res.end();
}
try {

@@ -42,9 +55,20 @@ const {invoke, request} = methodRoutes.resolve(req.method, req.url);

const handle = server.listen(options.port);
const serverStarting = new Promise((resolve) => {
const handle = server.listen(options.port, () => {
debug(`Server started at ${options.port}`);
return {
stop() {
handle.close();
}
};
const instance = {
stop() {
debug(`Closing server at ${options.port}`);
handle.close();
}
};
resolve(instance);
});
});
launcher.registerStartingInstance(options.port, serverStarting);
return serverStarting;
};

@@ -51,0 +75,0 @@

{
"name": "@wix/be-server",
"version": "1.0.115",
"version": "1.0.116",
"author": "Mantas Indrašius <mantasi@wix.com>",

@@ -12,3 +12,3 @@ "publishConfig": {

"build": "tsc --declaration",
"test": "mocha test lib/**/*.spec.js --reporter mocha-env-reporter",
"test": "mocha test/**/*.e2e.js lib/**/*.spec.js --reporter mocha-env-reporter",
"release": "wnpm-release --no-shrinkwrap"

@@ -15,0 +15,0 @@ },

@@ -28,6 +28,4 @@ const beServer = require('..');

}))
.withBindings([{
binding: http(get('/api/dynamic-echo'), echoMessage, echoMessage),
invoke: (message) => message
}])
.withBindings(
http(get('/api/dynamic-echo'), echoMessage, echoMessage).bind((message) => message))
.start({ port: 9901 });

@@ -34,0 +32,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc