question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Socket Engine - Framework and Platform agnostic Angular Universal rendering.

See original GitHub issue

While I personally think that having a separate NodeJS Express server for handling SSR is good solution it’s not always possible to do so in every environment. Therefore we can provide a simple and easily solution that enables Universal on any platform or framework.

Angular Socket Engine

Draft implementation: https://github.com/angular/universal/pull/999 Framework and Platform agnostic Angular Universal rendering.

Usage Server

npm install @nguniversal/socket-engine @nguniversal/common --save

const socketEngine = require('@nguniversal/socket-engine');

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./dist/server/main');

socketEngine.startSocketEngine(AppServerModuleNgFactory);

This will the socket engine which internally hosts a TCP Socket server.
The default port is 9090 and host of localhost You may want to leave this as a plain .js file since it is so simple and to make deploying it easier, but it can be easily transpiled from Typescript.

Usage Client

Your client can be whatever language, framework or platform you like.
Aslong as it can connect to a TCP Socket (which all frameworks can) then you’re good to go.

This example will use JS for simplicity

import * as net from 'net';

const client = net.createConnection(9090, 'localhost', () => {
  const renderOptions = {id: 1, url: '/path',
    document: '<app-root></app-root>'} as SocketEngineRenderOptions;
  client.write(JSON.stringify(renderOptions));
});

client.on('data', data => {
  const res = JSON.parse(data.toString()) as SocketEngineResponse;
  server.close();
  done();
});

GRPC Engine

Draft implementation: https://github.com/angular/universal/pull/1003 Another proposed implementation thats very similar to the above Socket Engine, but instead of using a TCP Socket as the transport it uses GRPC.
This will make consuming it much easier since we can provide the .proto file and you’re good to go.

Feel free to discuss advantages of both implementations.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:43
  • Comments:37 (5 by maintainers)

github_iconTop GitHub Comments

18reactions
dhergescommented, Jun 5, 2018

When you ask for “when is it ready?” ask first “what could I do to make it quicker/better?”

13reactions
Toxicablecommented, May 22, 2018

@lionskape We’re happy to hear why one might be better than the other. We may also end up implementing both, since they’re simply implementations of an Interface they’re relatively easy to maintain

Read more comments on GitHub >

github_iconTop Results From Across the Web

nguniversal/socket-engine NPM - npm.io
Angular Universal Socket Engine. Framework and Platform agnostic Angular Universal rendering. Deprecated. This package has been deprecated.
Read more >
Angular Universal: real app problems - InDepth.Dev
The project makes server-side rendering possible in Angular. ... Another package Socket Engine is a framework-agnostic that theoretically allows any backend ...
Read more >
Server-side rendering (SSR) with Angular Universal
Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces ......
Read more >
Perform Angular server-side (pre-)rendering with Cloud Build
This task helps you setup a new Google Cloud project in which to run an Angular application. (You can also use an existing...
Read more >
12 Best Nodejs Frameworks for App Development in 2022
Sails is a frontend-agnostic-backend platform. However, this lightweight framework uses Express for HTTP requests and Socket.io for WebSockets.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found