Skip to main content

Handling Affiliate Cookies and Internationalized Routing in Next.js Middleware

· 3 min read
samundrak
JavaScript Dev

When building complex Next.js applications, middleware becomes an essential place to handle cross-cutting concerns such as authentication, localization, and tracking. One common challenge is setting cookies conditionally while ensuring that the middleware returns the correct routing response—especially when dealing with internationalized routing (i18n).

In this article, I’ll walk you through a practical example where we:

  • Set an affiliate tracking cookie based on the request referer
  • Use next-i18n-router middleware to route users based on locale
  • Avoid common pitfalls that cause 404s or missing cookies

Create blob and file from data uri

· One min read
samundrak
JavaScript Dev

Creating a file in client side (browser) is something we may have to do frequently. Every time I have to work with it I try to google and always end up with the long solution. After digging and doing some research I found this clean way to create file and blob from data uri.

Adapter Design Pattern

· One min read
samundrak
JavaScript Dev

The adapter pattern helps us to connect or communicate with two or more than two interfaces that are not compatible with each other. In a simple word if we have to consume data from a source which our current implementation doesn't support then we can use this pattern to communicate with incompatible sources.

Proxy design pattern in short

· 2 min read
samundrak
JavaScript Dev

We can use the Proxy pattern whenever we want to control access to any third-party library or service which can be resource-heavy or expensive. For example, if we are integrating an SMS service in our application and sending every SMS can cost us a cent and there can be many chances where SMS content can be duplicated. In such a context we can create a proxy pattern that controls twillo access and help us to dedupe messages.

Policy and Details in Software Architect

· One min read
samundrak
JavaScript Dev

Software systems can be decomposed into two major elements which are Policy and Details. The policy element embodies all the business rules and procedures. It is where the true value of the system lives.

The details are those things that are necessary to enable humans, other systems, and programmers to communicate with the policy, but that do not impact the behavior of the policy at all. They include IO devices, databases, web systems, servers, frameworks, communication protocols, and so forth.

SQL and defination of DDL, DML, DCL and DIL

· One min read
samundrak
JavaScript Dev

The first version of SQL was developed by IBM called Sequel as part of the System R project. SQL stands for structured query language and is a combination of simple english words. SQL is used as a language to communicate with database. Same SQL code can run on multiple database albeit some database have slightly different syntax than others but still they have to maintain specification of SQL.

Entity and Entity Relationship model

· One min read
samundrak
JavaScript Dev

ER or Entity Reletionship model is used to create and model the data which is simple, non technical and easily understood by people describing a diagram with relation. It helps us to analyze requirements systematically to produce a well designed database.