DEV Community

Kenneth Lum
Kenneth Lum

Posted on

1 1

To tell what the web server is, right inside of a webpage

Sometimes if we start a local webserver, or if we use other online pages, we would like to find out what webserver it is, and it is possible to do it right inside of the webpage. We can fetch something, and look at the response header by res.headers.get("Server"):

fetch("foo.txt").then((res) => {
  document.querySelector(
    "#server-note"
  ).innerHTML = `The server is ${JSON.stringify(res.headers.get("Server"))}`;
});
Enter fullscreen mode Exit fullscreen mode

Demo: https://jsfiddle.net/KennethKinLum/80td3s4f/

The server for

Webserver in the header
Node.js's live-server nothing (null)
Ruby's ruby -run -e httpd . -p 8080 WEBrick/1.4.2 (Ruby/2.6.3/2019-04-16)
Python 2's python -m SimpleHTTPServer 8080 SimpleHTTP/0.6 Python/2.7.16
Python 3's python3 -m http.server 8080 SimpleHTTP/0.6 Python/3.8.2
JSFiddle nginx
Codesandbox cloudflare
macOS Big Sur's webserver Apache/2.4.46 (Unix)

It is possible to tell the user-agent as well, using navigator.userAgent.

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)