Sign inSign up

yannoff/node-api

By yannoff

•Updated almost 3 years ago

A docker service to expose node/npm/yarn commands over http

Image
0

1.7K

yannoff/node-api repository overview

⁠docker-node-api

A docker service to expose node/npm/yarn commands over http

Github Repository: https://github.com/yannoff/docker-node-api/⁠

WARNING: This is a work in progress

⁠Purpose

Modern web application frameworks such as symfony, are often coupled with yarn or node for assets building and compiling.

As a consequence, those javascript libraries have to be installed in the PHP container, which is, from the docker point of view, not the best practice.

This project aims at separating the javascript part: node, NPM or yarn commands are bundled in a dedicated container which exposes an http API.

For instance,

curl http://0.0.0.0:5000/yarn+install

will issue a

yarn install

command in the node server container.

On the other hand, the PHP container will have alternative node, yarn & npm scripts, acting as pass-thru to the API endpoint.

For instance:

#!/bin/bash
#
# /usr/bin/node script example
#

# Collect arguments to build the encoded URL
args=
while [ $# -gt 0 ]
do
    args="${args}%20$1"
    shift 1
done

# Here we assume the node-api service is named "node"
# The hostname must be changed to match the docker-compose.yaml services config 
curl http://node:5000/node${args} 2>/dev/null

⁠Core files
⁠config.json

The config.json file allows fine-tuning on the API server.

nametypedescription
allowed-commandslistList of the commands exposed to the API
Any other command call will result in a 403 Forbidden response code.
portintThe port the server will listen to (1)

(1) Beware: this value must match the exposed port in the docker-compose.yaml config.

⁠server.js

The API entrypoint server script.

⁠Samples

A few sample files are provided:

⁠Notes

⁠Assetic

To support kriswallsmith/assetic⁠, the php and node services config must follow a few principles in the docker-compose.yaml:

  • The working_dir must be the same in either containers
  • The /tmp path must be shared between the two containers

⁠License

Licensed under the MIT License⁠

Tag summary

Content type

Image

Digest

Size

62.7 MB

Last updated

about 5 years ago

docker pull yannoff/node-api