Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running old and new platform at the same time #12520

Closed
kimjoar opened this issue Jun 27, 2017 · 2 comments
Closed

Running old and new platform at the same time #12520

kimjoar opened this issue Jun 27, 2017 · 2 comments
Labels
Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@kimjoar
Copy link
Contributor

kimjoar commented Jun 27, 2017

We need to figure out how to run the new and the old platform at the same time. There are several options to accomplish that:

Running old platform as a sub-system of the new platform

If we go this route, new platform will be handling all incoming requests with expressjs. If it can handle request completely on its own it will do so without even touching the old platform, otherwise we'll "redirect" request to the old platform with the help of server.inject API provided by HapiJS. This may look like this:

const app = express();
app.all('/*', (expressRequest, expressResponse) => {
  hapiServer.inject({
    method: expressRequest.method,
    headers: expressRequest.headers,
    url: expressRequest.path,
    payload: expressRequest.payload
  }, (hapiResponse) => {
    Object.keys(hapiResponse.headers).forEach((headerKey) => {
      expressResponse.header(headerKey, hapiResponse.headers[headerKey]);
    });
    
    expressResponse.status(hapiResponse.statusCode);
    expressResponse.send(hapiResponse.rawPayload);
  });
});

It looks like server.inject API provides everything we need (validation of parameters, all server hooks are called etc.) including ability to set request.auth field if needed (to mark request as already authenticated).

This approach also applies nicely to our plan of gradual migration to the new platform: once some logic is fully supported by a new platform then it's no longer "redirected" to the old platform.

Relying on expressjs also means that we'll have to do a bit more work in the new platform initially though:

  • handling of https-http redirect and SSL setting in general;
  • serving of static files;
  • handling of jade templates;
  • dealing with dev proxy stuff.

Exposing new platform API to the old platform

If we go this route, then entire HTTP stack will be managed by the old platform (HapiJS) and new platform we'll have to expose pure programmatic APIs that old platform can leverage.

@kimjoar kimjoar added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Jun 27, 2017
@azasypkin
Copy link
Member

Just quick update regarding to Running old platform as a sub-system of the new platform, it turned out the following things work fine with expressjs-hapijs-bridge (aka server.inject) and there is no need to implement them in the platform at this stage:

  • serving of static files;
  • handling of jade templates;
  • dealing with dev proxy stuff.

@kimjoar
Copy link
Contributor Author

kimjoar commented Oct 10, 2017

Closed by #13844

@kimjoar kimjoar closed this as completed Oct 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

No branches or pull requests

3 participants