Routes Server Framework

1.1.114 · active · verified Sun Apr 19

Routes Framework is a server-side framework designed for building web applications and APIs, emphasizing a structured approach to defining routes and handling requests. As of version 1.1.114, it provides core functionalities for HTTP request routing, likely including middleware support and request/response object manipulation. Without public documentation, specific details regarding its release cadence, architectural patterns, or key differentiators against established frameworks like Express, Koa, or Fastify are not available. It is presumed to be a Node.js-based solution, potentially offering a custom, opinionated approach to server development for its primary users, 'AwakenMyCity'. The exact feature set, performance characteristics, and community support remain undocumented for external reference.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting up a basic HTTP server, defining routes, using middleware, and mounting a router in the `routes-framework`.

import { Application, Router } from 'routes-framework';
import { createServer } from 'http';

interface CustomRequest extends Request {
  userId?: string;
}

const app = new Application();
const apiRouter = new Router();

// A simple middleware function
apiRouter.use((req: CustomRequest, res, next) => {
  console.log('API Request received:', req.method, req.url);
  // Simulate authentication
  if (req.headers['authorization'] === 'Bearer secret-token') {
    req.userId = 'user123';
    next();
  } else {
    res.statusCode = 401;
    res.end('Unauthorized');
  }
});

// Define a route on the router
apiRouter.get('/hello', (req: CustomRequest, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end(`Hello from API, User ID: ${req.userId}`);
});

// Mount the router under a base path
app.use('/api', apiRouter);

// A basic root route
app.get('/', (req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Welcome to Routes Framework!');
});

// Start the server
const PORT = process.env.PORT ?? 3000;
const server = createServer(app.handleRequest.bind(app)); // Assuming an 'handleRequest' method

server.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
  console.log('Try: curl http://localhost:3000');
  console.log('Try: curl -H "Authorization: Bearer secret-token" http://localhost:3000/api/hello');
  console.log('Try: curl http://localhost:3000/api/hello');
});

view raw JSON →