четверг, 22 августа 2019 г.

Doctrine persists extra entities at update/merge fix

If you have batch create and update action simultaneously (persisting entity if it doesn't exists in DB or update it otherwise), made like in this documentation, and you noticed that it creates redundant entities, it means Doctrine think they are new. Enable "detach" cascade (transitional) operation in Doctrine like this:

/**
* @OneToMany(targetEntity="Customer", mappedBy="product", cascade={"detach"})
*/
protected $customers;

If you are not in dev environment, do not forget to run orm:clear-cache:metadata command.

четверг, 1 августа 2019 г.

[nodejjs] [websocket] Specified protocol was not requested by the client fix

If you have this error:

Error: Specified protocol was not requested by the client.
    at WebSocketRequest.accept (/proj/node_modules/websocket/lib/WebSocketRequest.js:289:19)

this means you have to create a connection at client side like this:

var connection = new WebSocket('ws://127.0.0.1:3000', 'echo-protocol');

instead of this:

var connection = new WebSocket('ws://127.0.0.1:3000');

Also this means you should to handle it at server side not to crash your server.

[Nodejs] Express + Websocket: Connection closed before receiving a handshake response

In case this error you should pass Express listen() return result to WebSocketServer() like this:

wsServer = new WebSocketServer({
    httpServer: app.listen(3000),
    port: 3001,
});

Full example:
var WebSocketServer = require('websocket').server;
var path = require('path');
var express = require('express');
var app = express();
app.use(express.static(path.join(__dirname, 'public')));

app.get('/', function(req, res){
    res.render('index.html');
});
console.log(`Server running on port ${process.env.PORT}`);

wsServer = new WebSocketServer({
    httpServer: app.listen(3000),
    port: 3001,
});