Socket
Socket
Sign inDemoInstall

@wix/be-server

Package Overview
Dependencies
Maintainers
4
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.2 to 1.0.3

lib/message-types.js

7

lib/routes.js

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

module.exports = function routes(services) {
module.exports = function routes(services, messageTypes) {
const routes = {};

@@ -15,2 +15,4 @@

const methodRoutes = serviceRoutes[methodName];
const method = service.methods[methodName];
const requestMessage = messageTypes.lookup(method.parent, method.requestType);

@@ -27,3 +29,4 @@ Object.keys(methodRoutes).forEach((httpMethod) => {

pattern: new UrlPattern(fromCurly(path)),
method: service.methods[methodName],
method,
requestMessage,
implementation: bindings[methodName]

@@ -30,0 +33,0 @@ });

const routes = require('./routes');
const messageTypes = require('./message-types');
const {expect} = require('chai');

@@ -73,4 +74,4 @@ const protobufjs = require('protobufjs');

service
})));
})), messageTypes(parsed.root));
}
});
const {create} = require('@wix/proto-packages');
const startServer = require('./server');
const defaultContextDir = require('find-root')(process.argv[1]);
const messageTypes = require('./message-types');

@@ -59,3 +60,4 @@ module.exports = {

...options,
services
services,
messageTypes: messageTypes(loadedContext)
});

@@ -62,0 +64,0 @@ }

@@ -5,3 +5,3 @@ const http = require('http');

module.exports = function start(options) {
const methodRoutes = routes(options.services)
const methodRoutes = routes(options.services, options.messageTypes);

@@ -22,3 +22,3 @@ const server = http.createServer(async(req, res) => {

try {
resolve(await execute(route, res, JSON.parse(data)));
resolve(await execute(route, res, request, JSON.parse(data)));
} catch(e) {

@@ -53,7 +53,13 @@ reject(e);

async function execute(route, res, body) {
const result = await route.implementation(body);
async function execute(route, res, request, body) {
const requestMessage = route.requestMessage;
console.log(request, body);
const message = requestMessage.fromValue([request, body]);
const result = await route.implementation(message);
res.setHeader('Content-Type', 'application/json');
res.write(JSON.stringify(result));
}
{
"name": "@wix/be-server",
"version": "1.0.2",
"version": "1.0.3",
"author": "Mantas Indrašius <mantasi@wix.com>",

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

"dependencies": {
"@wix/be-http-binding": "^1.0.1",
"@wix/be-http-binding": "^1.0.7",
"@wix/proto-packages": "^1.0.22",

@@ -27,0 +27,0 @@ "find-root": "^1.1.0",

@@ -18,3 +18,4 @@ const beServer = require('..');

echo: (message) => message,
postEcho: (message) => message
postEcho: (message) => message,
typesEcho: (message) => message,
})

@@ -55,2 +56,26 @@ .start({ port: 9901 });

});
it.only('should post typed message', async() => {
const response = await fetch('http://localhost:9901/api/echo/i-am-a-string?int=99', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ nested: {
message: 'Hello'
}})
});
expect(response.status).to.equal(200);
const body = await response.json();
expect(body).to.deep.equal({
int: 99,
str: 'i-am-a-string',
nested: {
message: 'Hello'
}
});
});
});

Sorry, the diff of this file is not supported yet

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