Serving Requests on IPv6 with Nginx

Serving Requests on IPv6 with Nginx

After a little back and forth, we realized that our web server lacked IPv6 support. We weren't listening to the requests made on IPv6

A few weeks ago one of our readers reached out on our support channel to tell us that our site wouldn't work for them no matter what.

It simply wouldn't load on their browser (Chrome).

After a little back and forth, we realized that our web server lacked IPv6 support. We weren't listening to the requests made on IPv6. If you don't know already IPv6 stands for Internet Protocol version 6, and it is intended to replace IPv4 network which is what our original web, as-is, has had a run on for the last two decades.

Google is out with stats on IPv6 adoption lately (as of October 2018) and the numbers are rising steadily. Over twenty five percent of the Internet is now using IPv6  and from the graph it appears that well over half would be onboard in the coming few years. More importantly, a % of those who are on IPv6 already are exclusively so and cannot see your content if the website isn't configured to serve on the new protocol. (Updated per tweet.)

ipv6 adoption @bubblin

Through this quick post we will configure our web app/site for the new protocol.

This is how I set it up on Bubblin.

The Quad-A Record.

The first step is to add an AAAA Record on your DNS Manager. We needed a public IP on IPv6 so I made a request to our hosting provider (Linode) to provide me with one.

Once they responded, I went ahead and added our public IPv6 on the Remote Access Panel, like so:

AAAA record linode

I added the ugly looking records with IPv6 option (bottom three) as screenshot-ted above. Since changes to DNS take some time to percolate we'll leave the DNS manager here and focus on configuring our app-server nginx for IPv6 next.

Nginx on IPv6

Now Bubblin is delivered on a strict https protocol so we are effectively a permanent on redirecting all our traffic (from http →) to https.

We use the Letsencrypt and Certbot to secure Bubblin with industry-grade SSL.

Shown below is an excerpt from our nginx.conf.erb on production:


#  $ sudo vi ~/.etc/nginx/sites-available/bubblin_production
#  add listen [::]:80 ipv6only=on; for requests via insecure protocol (http).

server {
    listen 80;
    listen [::]:80 ipv6only=on; 
    server_name <%= fetch(:nginx_server_name) %> www.<%= fetch(:nginx_server_name) %>;
    rewrite ^(.*) https://$host$1$request_uri permanent;

#  add listen [::]:443 to listen for requests over IPv6 on https.
server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;  
  server_name www.<%= fetch(:nginx_server_name) %>;

  # Other SSL related stuff here.

  rewrite ^ https://$host$1$request_uri permanent; 


# add listen [::]:443 ssl http2; on the final server block.

server {

  // Plenty of nginx config here.

  listen 443 ssl http2; # managed by Certbot
  listen [::]:443 ssl http2;

  # Add HSTS header with preloads
  add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";


Notice the listen [::]:80 ipv6only=on; directive inside the server block and the HSTS directive at the bottom.

To test your nginx configuration:

$ sudo nginx -t

// success

$ sudo nginx -s reload

Hoping that your DNS percolated by the time the nginx was cofigured (sometimes it may take up to 24 hours), now it is time to test if the website is available on IPv6:

$ curl -6

The HTML page from your site should be served correctly.

That's all folks.

Hi, I'm Marvin Danig, CEO and Cofounder of Bubblin.

You might want to follow and connect with me on Twitter or  Github?

P.S.: Reading more books on web will help your attention span.

30s ad

AJAX using Javascript and JQuery + 2 Projects

Modern JavaScript: Building Real-World, Real-Time Apps

Essentials in JavaScript ES6 - A Fun and Clear Introduction

JavaScript the Basics - JavaScript for Beginners

Beginning ES6, The Next Generation of JavaScript

AWS Certified Solution Architect Associate

AWS Certified Solution Architect Associate

This course will help you in the final preparation steps for your AWS Certified Solution Architect Associate - Certification Exam.

In this course , we will go through the different concepts that get asked in the exam and map them to the different domain objectives for the exam.

This is good revision guide before you attempt the certification exam

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow us on Facebook | Twitter

Further reading about AWS

A Complete Guide on Deploying a Node app to AWS with Docker

AWS Certified Solutions Architect - Associate 2019

AWS Lambda vs. Azure Functions vs. Google Functions

AWS Certified Developer - Associate 2019

Create and Deploy AWS and AWS Lambda using Serverless Framework

Introduction To AWS Lambda

Why Azure is Better Than AWS

How to implement server-side pagination in React with Node.js

How to implement server-side pagination in React with Node.js

In this article, you'll see a simple example of how to implement server-side pagination in React with a Node.js backend API

The example contains a hard coded array of 150 objects split into 30 pages (5 items per page) to demonstrate how the pagination logic works. Styling of the example is done with Bootstap 4.

Running the React + Node Pagination Example Locally
  1. Install NodeJS and npm from
  2. Download or clone the tutorial project source code from
  3. Install required npm packages of the backend Node API by running the npm install command in the /server folder.
  4. Start the backend Node API by running npm start in the /server folder, this will start the API on the URL http://localhost:4000.
  5. Install required npm packages of the frontend React app by running the npm install command in the /client folder.
  6. Start the React frontend app by running npm start in the /client folder, this will build the app with webpack and automatically launch it in a browser on the URL http://localhost:8080.
Server-Side (Node.js) Pagination Logic

Below is the code for the paged items route (/api/items) in the node server file (/server/server.js) in the example, it creates a hardcoded list of 150 items to be paged, in a real application you would replace this with real data (e.g. from a database). The route accepts an optional page parameter in the url query string, if the parameter isn't set it defaults to the first page.

The paginate() function is from the jw-paginate package and accepts the following parameters:

  • totalItems (required) - the total number of items to be paged
  • currentPage (optional) - the current active page, defaults to the first page
  • pageSize (optional) - the number of items per page, defaults to 10
  • maxPages (optional) - the maximum number of page navigation links to display, defaults to 10

The output of the paginate function is a pager object containing all the information needed to get the current pageOfItems out of the items array, and to display the pagination controls in the React frontend, including:

  • startIndex - the index of the first item of the current page (e.g. 0)
  • endIndex - the index of the last item of the current page (e.g. 9)
  • pages - the array of page numbers to display (e.g. [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ])
  • currentPage - the current active page (e.g. 1)
  • totalPages - the total number of pages (e.g. 30)

I've set the pageSize to 5 in the CodeSandbox example above so the pagination links aren't hidden below the terminal console when the container starts up. In the code on GitHub I didn't set the page size so the default 10 items are displayed per page in that version.

The current pageOfItems is extracted from the items array using the startIndex and endIndex from the pager object. The route then returns the pager object and current page of items in a JSON response.

// paged items route
app.get('/api/items', (req, res, next) => {
    // example array of 150 items to be paged
    const items = [...Array(150).keys()].map(i => ({ id: (i + 1), name: 'Item ' + (i + 1) }));
    // get page from query params or default to first page
    const page = parseInt( || 1;
    // get pager object for specified page
    const pageSize = 5;
    const pager = paginate(items.length, page, pageSize);
    // get page of items from items array
    const pageOfItems = items.slice(pager.startIndex, pager.endIndex + 1);
    // return pager object and current page of items
    return res.json({ pager, pageOfItems });

Client-Side (React) Pagination Component

Since the pagination logic is handled on the server, the only thing the React client needs to do is fetch the pager information and current page of items from the backend, and display them to the user.

React Home Page Component

Below is the React home page component (/client/src/HomePage/HomePage.jsx) from the example. The loadPage() method determines the current page by checking for the value in the url query params or defaulting to page 1, then fetches the pager object and pageOfItems for the current page from the backend API with an HTTP request.

The componentDidMount() React lifecycle hook kicks off the first call to loadPage() when the React component loads, then the componentDidUpdate() React lifecycle hook calls loadPage() when the page is changed with the pagination links.

The component renders the current page of items as a list of divs, and renders the pagination controls using the data from the pager object. Each pagination link sets the page query parameter in the url using the Link React Router component with the search parameter.

The CSS classes used are all part of Bootstrap 4.3, for more info see

import React from 'react';
import { Link } from 'react-router-dom';
class HomePage extends React.Component {
    constructor(props) {
        this.state = {
            pager: {},
            pageOfItems: []
    componentDidMount() {
    componentDidUpdate() {
    loadPage() {
        // get page of items from api
        const params = new URLSearchParams(;
        const page = parseInt(params.get('page')) || 1;
        if (page !== this.state.pager.currentPage) {
            fetch(`/api/items?page=${page}`, { method: 'GET' })
                .then(response => response.json())
                .then(({pager, pageOfItems}) => {
                    this.setState({ pager, pageOfItems });
    render() {
        const { pager, pageOfItems } = this.state;
        return (
            <div className="card text-center m-3">
                <h3 className="card-header">React + Node - Server Side Pagination Example</h3>
                <div className="card-body">
                    { =>
                        <div key={}>{}</div>
                <div className="card-footer pb-0 pt-3">
                    {pager.pages && pager.pages.length &&
                        <ul className="pagination">
                            <li className={`page-item first-item ${pager.currentPage === 1 ? 'disabled' : ''}`}>
                                <Link to={{ search: `?page=1` }} className="page-link">First</Link>
                            <li className={`page-item previous-item ${pager.currentPage === 1 ? 'disabled' : ''}`}>
                                <Link to={{ search: `?page=${pager.currentPage - 1}` }} className="page-link">Previous</Link>
                            { =>
                                <li key={page} className={`page-item number-item ${pager.currentPage === page ? 'active' : ''}`}>
                                    <Link to={{ search: `?page=${page}` }} className="page-link">{page}</Link>
                            <li className={`page-item next-item ${pager.currentPage === pager.totalPages ? 'disabled' : ''}`}>
                                <Link to={{ search: `?page=${pager.currentPage + 1}` }} className="page-link">Next</Link>
                            <li className={`page-item last-item ${pager.currentPage === pager.totalPages ? 'disabled' : ''}`}>
                                <Link to={{ search: `?page=${pager.totalPages}` }} className="page-link">Last</Link>
export { HomePage };

The tutorial code is available on GitHub

Web Service Tutorial: Streaming Data with Spring Boot RESTful

Web Service Tutorial: Streaming Data with Spring Boot RESTful

In this article, we are going to look at an example to download files using StreamingResponseBody. In this approach, data is processed and written in chunks to the OutputStream.

In this article, we are going to look at an example to download files using StreamingResponseBody. In this approach, data is processed and written in chunks to the OutputStream.

Streaming data is a radical new approach to sending data to web browsers which provides for dramatically faster page load times. Quite often, we need to allow users to download files in web applications. When the data is too large, it becomes quite a challenge to provide a good user experience.

Spring offers support for asynchronous request processing via StreamingResponseBody. In this approach, an application can write data directly to the response OutputStream without holding up the Servlet container thread. There are a few other methods in Spring to handle asynchronous request processing.

Setting Up Spring Boot Project

Create a sample Spring Boot application. Here is my sample project structure. I have created the project manually, but you could also create using Spring Intializer.

Project structure

Let us add some basic dependencies to Maven POM.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""
        <relativePath />

We will now create a controller and add an API endpoint for download. Here is my complete controller.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
import javax.servlet.http.HttpServletResponse;
@RequestMapping ("/api")
public class DownloadController {
    private final Logger logger = LoggerFactory.getLogger(DownloadController.class);
    @GetMapping (value = "/download", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<StreamingResponseBody> download(final HttpServletResponse response) {
        StreamingResponseBody stream = out -> {
            final String home = System.getProperty("user.home");
            final File directory = new File(home + File.separator + "Documents" + File.separator + "sample");
            final ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream());
            if(directory.exists() && directory.isDirectory()) {
                try {
                    for (final File file : directory.listFiles()) {
                        final InputStream inputStream=new FileInputStream(file);
                        final ZipEntry zipEntry=new ZipEntry(file.getName());
                        byte[] bytes=new byte[1024];
                        int length;
                        while (( >= 0) {
                            zipOut.write(bytes, 0, length);
                } catch (final IOException e) {
                    logger.error("Exception while reading and streaming data {} ", e);
        };"steaming response {} ", stream);
        return new ResponseEntity(stream, HttpStatus.OK);

In this API endpoint, we are reading multiple files from a directory and creating a zip file. We are executing this process within StreamingResponseBody*. It writes data directly to an OutputStream before passing that written information back to the client using aResponseEntity. *This means that the download process will start immediately on the client, while the server is processing and writing data in chunks.

Start the server and test this endpoint using http://localhost:8080/api/download.

When using StreamingResponseBody, it is highly recommended to configure TaskExecutor used in Spring MVC for executing asynchronous requests. TaskExecutor is an interface that abstracts the execution of a Runnable.

Let us configure the TaskExecutor. Here is the AsyncConfiguration class which configures timeout using WebMvcCofigurer and also registers an interceptor that is called when there's a timeout in case you need some special handling.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.async.CallableProcessingInterceptor;
import org.springframework.web.context.request.async.TimeoutCallableProcessingInterceptor;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.concurrent.Callable;
public class AsyncConfiguration implements AsyncConfigurer {
    private final Logger log = LoggerFactory.getLogger(AsyncConfiguration.class);
    @Bean (name = "taskExecutor")
    public AsyncTaskExecutor getAsyncExecutor() {
        log.debug("Creating Async Task Executor");
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        return executor;
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return new SimpleAsyncUncaughtExceptionHandler();
    /** Configure async support for Spring MVC. */
    public WebMvcConfigurer webMvcConfigurerConfigurer(AsyncTaskExecutor taskExecutor, CallableProcessingInterceptor callableProcessingInterceptor) {
        return new WebMvcConfigurer() {
            public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
    public CallableProcessingInterceptor callableProcessingInterceptor() {
        return new TimeoutCallableProcessingInterceptor() {
            public <T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception {
                return super.handleTimeout(request, task);


Using StreamingResponseBody, we can now stream data easily for highly-concurrent applications. I hope you enjoyed this article. Let me know if you have any comments or suggestion in the comments section below.

The example for this article can be found on GitHub repository.

Using Custom Authentication Backends in Django

Using Custom Authentication Backends in Django

If you’re working in an organization with an established product line that serves live users, supporting a new site with Django probably means integrating with an existing authentication system.

Using Custom Authentication Backends in Django

If you’re working in an organization with an established product line that serves live users, supporting a new site with Django probably means integrating with an existing authentication system. Many organizations use widely-adopted authentication systems provided by services like Google, Facebook, or GitHub. A few Python packages provide authentication integration with these services, but most of them expect you to be handling the final user accounts on with Django. What happens when you need to work with user accounts that live in another system altogether?

In this article, you’ll see the interface that Django exposes for authenticating to an external system. By the end, you should understand the pieces involved in mapping an external system’s information to Django’s native User objects in order to work with them on your own site.

Django’s default authentication

In the Django User Authentication System, we covered the basics of how default authentication works in Django. Ultimately, you can interact with User objects and understand if a user is_authenticated or not. Using the default authentication system, you can make use of many of Django’s built-in features like its login and logout views and password reset workflow.

When working with an external authentication system, you have to manage these pieces yourself. Some of them may not make sense to you depending on how your authentication system works.

Authentication backends

As with many of Django’s systems, authentication is modeled as a plugin system. Django will try to authenticate users through a series of authentication backends. The default backend checks a user’s username and password against all the existing User objects in the database to authenticate them. The AUTHENTICATION_BACKENDS setting is your entrypoint to intercept this workflow and point Django to your external system.

An authentication backend is a class that, minimally, implements two methods:

  • get_user(user_id) — a user_id can be whatever unique identifier your external system uses to distinguish users, and get_user returns either a user object matching the given user_id or None.
  • authenticate(request, **credentials) — the request is the current HTTP request, and the credentials keyword arguments are whatever credentials your external system needs to check if a user should be authenticated or not. This is often a username and password, but it could be an API token or some other scheme. authenticate returns an authenticated User object or None.

Inside your authentication backend’s authenticate method, you can pass along the credentials to your external system via a REST API or another common authentication scheme like LDAP or SAML.

Using the wonderful Yes or No? API, you could build an authentication backend that authenticates a user occasionally if the API permits:

import requests

class FickleAuthBackend:
    def authenticate(self, request, username):
        response = requests.get(
        return User(username=username, password='') if response['answer'] == 'yes' else None

While authenticate can return a user object or None, it may also return an AnonymousUser object, or raise PermissionDenied to explicitly halt any further authentication checks. This allows for a variety of ways to proceed, and anonymous users may still have certain permissions. You’ll want to account for that in your middleware and views.

If the external user service provides additional information about the user, get_user might be a good place to grab some of that data. You can add attributes to the user object in authenticate before you return it if you’d like, but be careful of how many attributes you add dynamically.


I also covered Django’s permission scheme in The Django User Authentication System: when given a user, you can inquire about their permissions generally or against specific objects using the has_perm method. Custom authentication backends can override permission checking methods and Django will check against those first before falling back to its default checks. This allows you to make queries to your external system about permissions in addition to authentication:

... continue with Permissions and check out the code!

Dane Hillard has an upcoming book "Practices of the Python Pro" coming this month (October 2019)

Trending React Next Landing Page Collection

Trending React Next Landing Page Collection

<img src="*glM0PBInmbgJXOF3">

SuperProps — React Next Landing Page Templates
Welcome to React Next Landing Page, built with React, Next Js, Gatsby Js & Styled Components. NO jQuery!, We created reusable react components, and modern mono repo architecture, so you can build multiple apps with common components. You can use these landing for your react app. It’s super easy to deploy, we have provided complete firebase integration with it. You can host your next app into firebase along with other hosts like Now — ZEIT.

Trending React Next Landing Page Collection

Next Landing Page, built with React, Next JS, Gatsby JS & Styled Components. NO jQuery!

Best Portfolio Landing Pages Template.


SuperProps — React Next Portfolio Landing Page Templates is clean. Creative and highly customizable React, Next JS, Gatsby JS & Styled Components. Template for Agency and Personal Portfolio websites. Responsive based on React JS. This is one page for placing your information. All files and code have been well organized and nicely commented for easy to customize.

SaaS Modern Responsive React Next Landing Page Templates

SaaS Modern

SaaS Modern is a responsive, professional, and multipurpose SaaS, Software, Startup landing template powered by React Next Landing Page, built with React, Next JS, Gatsby JS & Styled Components. NO jQuery!. SaaS Modern is a powerful and super flexible tool, which suits best for any kind of landing pages. SaaS Modern is definitely a great kick starter for your web project.

SaaS Modern design is harmonious, clean and user-friendly

Best SaaS Landing Page Template SaaS Classic

SaaS Classic

SaaS Classic is responsive Unbounce Landing Page Template for SaaS & Software sites. It is clean, modern and creative design suitable for all type of SaaS & Software style websites. This template is the perfect combination of creativity and professionalism with simplicity on all sections.

Ride Sharing Landing Page Template

Ride Sharing

SuperProps Ride Sharing is highly customizable and is built with keeping real projects in mind. You can create Ride sharing, Taxicab, Food Delivery, and Transportation network company React Next Template. The template is specially designed keeping the needs of users in mind.

SaaS Product Landing Page Templates

SaaS Product Landing Page

SuperProps SaaS Product landing page is a responsive React, Next JS, Gatsby JS & Styled Components saas template.

Looking for a landing page for your saas product app or startup? You are at the right place. SuperProps SaaS Product is a perfect template which is easy to develop with and it has unlimited customization possibilities. It is created with modern vibrant colors and shapes.

Best App Landing Page Template SuperProps

App Landing Page Template

SuperProps App Landing is a clean and modern App Landing Page Template. Built with React Next Landing Page, built with React, Next JS, Gatsby JS & Styled Components. It has different homepage styles and color variations. Well organized and comment codes so it’s very easy to customize and use in your project according to your needs.

SuperProps Agency Landing Page Template

Agency Landing Page Template

Modern and flexible One-page Multipurpose React Next template that you can use for Agency, business, portfolio or company profile. It is fully responsive template and suitable for all type of business, corporate, portfolio, digital agency or any creative modern looking websites.

Web Hosting Landing Page Templates from ThemeForest

Web Hosting Template

Best React Next Web Hosting Website Templates.

You are always prepared and fully equipped for building a powerful and professional hosting site with React Next Landing Page, built with React, Next JS, Gatsby JS & Styled Components. NO jQuery! web hosting website templates.

Our Best Landing Pages & Templates the list is updated weekly