Skip to content

Instantly share code, notes, and snippets.

@cdrini
Created June 9, 2021 23:51
Show Gist options
  • Save cdrini/9c8c8ca5746ece7386b4c3b510dcf6f5 to your computer and use it in GitHub Desktop.
Save cdrini/9c8c8ca5746ece7386b4c3b510dcf6f5 to your computer and use it in GitHub Desktop.
Thoughts on OL server-side options

Thoughts on OL server-side options from 2021-06-09 call with @jdlrobson

Executing vue template from the python

This is apparently an option! @jdlrobson exploring with PyMiniRacer.

Custom webpack loader to import jsdef function from python files

This is one possibility; it would allow us to keep some of the rendering logic in python, and pull it in from the JavaScript.

Node-based call-out

If we have some node file that renders a Vue template, we can call it from the python and cache the result. Basically identical to the next option, but without a separate service. This might make it slightly easier to manage (and this would probably be better for a v0), but having a long lived service might have some speed improvements. Note caching will regardless be happing on the python side with our memcached servers; likely based on vue component name, and prop values.

We'd likely just augment this function to call the node file (and cache):

https://github.com/internetarchive/openlibrary/blob/1cf1b7791749754d1f114973d57b7fc65cfc3ec0/openlibrary/plugins/upstream/utils.py#L126-L158

Node-based rendering server

Would require a node-based call-out script thing, but long-lived in its own service; we basically only need to add something like this to our docker-compose, and it will largely just work in prod:

  # Create a new service that will start on `docker-compose up`.
  vue-rendering-server:
    # The default image, oldev:latest, has node on it! So can use it to start a Node
    # server if we want to.
    image: "${OLIMAGE:-oldev:latest}"

    ports:
      # Syntax is HOST:Container, so this will assume the container (i.e. start.sh in
      # this example) is exposing port 9099, and it will make that available on the
      # host machine at localhost:9099. Other services in the file (ex the web service)
      # will be able to access it at vue-rendering-server:9099
      - 9099:9099
    
    networks:
      # webnet is the network with the web (ie python) service on it; if we want this
      # accessible from the python, it'll need access
      - webnet

    # And the long-lived command that will be running on this server.
    command: node start.sh

Rendertron

IA is exploring a more client-side rendering driven experience, and exploring Rendertron (From the Google Chrome team!), a "Headless Chrome rendering solution", for rendering stuff server-side for browsers that don't support eg es6 modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment