While Logging the Request object in Express is amazingly easy, doing so with the response is not quite as straight forwards.

We need to utilize a couple of tricks and some patching to get things working smoothly and get all the information we are sending back to the client.

We can also use this technique to perform some other manipulation rather than just logging, some use cases might be:

  1. To Observe the response (Logging, Tracing)
  2. To Amend the response (Redacting information by origin for example or modify response for target audience)

The Middleware

Logging the Request

Firstly we need to create a basic middleware which…


In this post were going to bootstrap an Express application, bung on typescript and get GraphQL up and running in no time at all. 🚀

All the code discussed and given as examples is available in the repo and I encourage you to checkout the article tag for a nice snapshot.

https://github.com/JonathanTurnock/express-ts-graphql-template/tree/article-v1.0.0

We will be using ts-node in this example, it allows us to run typescript directly without any additional boilerplate 🤯. Feel free to add in transpiling if necessary 😒.

What we’ll get?

  • Typescript at the core
  • Tests run with Jest
  • Standard familiar Express app
  • GraphQL Query, Mutation and Subscriptions via Websockets


I recently came across a little known feature of Windows WSL. The ability to launch GUI apps!

I’ve started doing much more of my environment management in WSL rather than Windows recently, excellent tools from Jetbrains and VSCode make coding in this environment a doddle.

While installing some packages I noticed that I accidentally installed a desktop environment, this got me thinking, would it be possible to run some GUI tools.

Turns out it is and its incredibly easy!

Install XMing

You will need an X11 display server for windows.

I personally used https://en.wikipedia.org/wiki/Xming.

This allows the apps to be rendered on…


Photo by noor Younis on Unsplash

Introduction

It’s entirely possible to get your Spring Boot application up and running in docker in less than 10 minutes.

Let’s run through this process first in theory, then in practice. We will start by covering what we are trying to achieve, followed by installing some dependencies and making sure everything is in place to hit the ground running.

By the end we will have a fully working Spring boot application deployed to your local docker installation and we will have it running with health checks.

Theory

To run our application we are going to need:

  1. Webserver & Application
  2. Host & Execution…


Photo by Franck V. on Unsplash

1. Introduction

Many automation libraries exist for python which help scrape sites and perform testing. Projects like Roboform, BeautifulSoup and requests all provide excellent features.

One slightly lesser known name to Python projects is Selenium. It’s an industry accepted automation and testing framework for UI’s. Unlike other web browsing/scraping libraries it actually plays out inside a browser as though the system was being interacted with.

This approach gives test teams the ability to automate a whole suite of regression tests for a site. It also helps to overcome some challenges with regards to JavaScript in sites.

A major hurdle in web scraping…


Photo by Kin Li on Unsplash

Getting a Deployable Artifact

Picking up from where we left on in the previous guide, we are going to start to look into how we can work with our project and its files.

You should now be able to go ahead and trigger a Gradle build at the root of the project.

./gradlew build

This will trigger the following series of events:

  • UI module will produce a jar file at ui/dist/ng-spring-angular-mono-0.0.1-SNAPSHOT.jar
    - Gradle Calls node build script
    - Gradle bundles contents of build script output (ui/build) into a jar under static/…
  • Spring module is built - Usual Spring Boot Build Process Takes Place …


Photo by Max Nelson on Unsplash

If you have spent any amount of time with the Python programming language, you might have come across the main scope conditional. It looks something like this:

if __name__ == "__main__":
...

What this method does is perfectly summarised in the Python Docs for the standard library:

A module can discover whether or not it is running in the main scope by checking its own __name__, which allows a common idiom for conditionally executing code in a module when it is run as a script or with python -m but not when it is imported

(Docs.python.org, 2019)

Let’s take a…


Python is full of extremely powerful functional programming expressions. Across all programming languages, one of the most commonly used of these is the ternary operator.

We might recognize this operator from other languages as:

(condition) ? (return if true) : (return if false)

In comparison to most programming languages, Python has a somewhat unusual syntax and that’s because it’s not actually a ternary operator at all. Python has a Conditional Expression using the ifand else keywords to replace ? and :

Syntax

The syntax for this Conditional Expression can be summarised as:

(return if true) if (condition) else (return if false)


CORS is for security, ok, but why?

I don’t intend on making a long deep dive into CORS during this short blog. But we should know the fundamentals.

CORS is an access control mechanism. It’s designed to prevent unauthorised access to an API.

It uses HTTP headers to manage this ACL.

It uses Pre-flight requests when queries are sent across domains. So for example from your frontend server to your backend server.

The below flow chart, courtesy of Wikipedia highlights the path of a cross origin request.

By Bluesmoon — Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=42452713

Chances are if you have made a cross origin request using your frontend framework the browser has blocked it because…


A nifty feature of the Jetbrains IDE tools is the file nesting. You may have seen on occasion that the IDE will compress files of the same name into a tree with the parent at the top and the children below. Say for example when js is minified the .min.js file can be displayed in a tree display under the main .js file.

We can use this to our advantage when working with Angular by compressing the file tree’s which can become quite populated in a large project.

Looking at this home-page component we can see a rather cluttered native…

Jonathan Turnock

☕️Java 🍃 Spring 🐍Python 🐳Docker — Experienced Full Stack Java, Python, Angular and Electron developer.

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