With web projects running inside Docker containers.

To develop a web project¹ on a local machine, we usually launch a web-server listening at http://localhost:port.

In production, the url for this project is https://my-app.com.

We want to mimic the production environment on the local computer. How can we have a custom url and HTTPS, like https://my-app.local?

In this article, we are going to:

  • Create custom urls for several web projects, like my-app.local.
  • Set a reverse-proxy to route the requests to these urls to specific Docker containers.
  • Add HTTPS with self-signed certificates.

Prerequisites
I tested on Mac. It should work on other platforms, but I didn’t try.
- Have Docker on our computer.
- Several web projects run inside Docker containers on our local machine. (Here is an example)

Set a reverse proxy

We want to route requests to custom urls (like my-app.local) to specific web-servers. This is the role of a reverse proxy.

We are going to use nginx as a reverse-proxy. We could manually setup and configure nginx, but this has some…


How to setup Docker-compose to isolate a web application

Each computer has a specific environment: some tools and specific version of languages are globally installed, our applications share databases… When we work on a web project, the production server might be different from our computer. This is error prone.

Docker solves this problem by running applications in isolated environments.

In this article, we are going to

  • Take an existing Node.js / MongoDB application and make it work inside Docker containers.
  • Share content between the host and the container to avoid restarting the container after each modification.

Prerequisites
- install Docker on your computer.

The application

As an example, we’ll take a very simple Node.js / Express / MongoDB aplication. Here is the package.json of this app:

{
"name": "test-app",
"version": "0.1.0",
"main": "index.js",
"scripts": {
"dev": "nodemon ./index.js",
"start": "node ./index.js"
},
"dependencies": {
"express": "^4.16.3",
"mongoose": "^5.0.16"
},
"devDependencies": {
"nodemon": "^1.17.3"
}
}

It has two scripts:

  • dev: uses nodemon for…


How to use pure functions, closures and functions composition

In a previous article we went through the steps to Smooth a svg path with cubic bezier curves. Here, we are going to refactor this code with functional programming.

Image for post
Image for post

Functional programming is the process of building software by composing pure functions, avoiding shared state, mutable data, and side-effects.

From What is functional programming? by Eric Elliott

Imperative code has a few problems:

  • Functions can rely on external states (variables or functions referenced from a higher scope) which can have side effects.
  • There is no explicit relations between functions.

With a large codebase, this is difficult to maintain and test. Functional programming aims to solving these problems.

So let’s refactor the imperative code from the previous article and use concepts related to functional programming: pure functions, closures and functions composition.

What are we trying to achieve?

Given an array of tuples representing the coordinates of a…

About

François Romain

Freelance developer / designer → http://francoisromain.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store