or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-7/

HTTP Request Logger

Build a simple HTTP server that logs incoming requests using a middleware-based architecture.

Requirements

Create an HTTP server that:

  1. Accepts incoming HTTP requests on a configurable port
  2. Uses a middleware-based architecture with at least two middleware functions:
    • A logging middleware that logs request details (method, URL, timestamp) to the console
    • A response middleware that sends a JSON response containing request information
  3. Handles requests to any path
  4. Returns status 200 with JSON containing the request method and URL

Implementation

@generates

API

/**
 * Creates and starts an HTTP server with logging middleware.
 *
 * @param {number} port - The port number to listen on
 * @returns {object} The HTTP server instance
 */
function createLoggerServer(port) {
  // IMPLEMENTATION HERE
}

module.exports = { createLoggerServer };

Test Cases

  • When a GET request is made to /test, the server responds with status 200 and JSON containing the request method and URL @test
  • When a POST request is made to /data, the server responds with status 200 and JSON containing the request method and URL @test
  • The server logs each request to the console with timestamp, method, and URL @test

Dependencies { .dependencies }

cli { .dependency }

Provides HTTP server creation with middleware support.