npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@obinexuscomputing/aerossr

v0.1.0

Published

AeroSSR is a lightweight, flexible server-side rendering framework for Node.js applications. It provides built-in support for static file serving, middleware, routing, caching, and compression.

Downloads

79

Readme

AeroSSR

AeroSSR is a lightweight, flexible server-side rendering framework for Node.js applications. It provides built-in support for static file serving, middleware, routing, caching, and compression.

Features

  • Fast and efficient server-side rendering
  • Built-in static file serving with caching and compression
  • Flexible middleware system
  • TypeScript support with full type definitions
  • Customizable routing
  • CORS handling
  • Error management
  • Extensible logging
  • Cache management
  • ETag support

Installation

npm install @obinexuscomputing/aerossr

Quick Start

import { AeroSSR, StaticFileMiddleware } from '@obinexuscomputing/aerossr';

// Create server instance
const app = new AeroSSR({
  port: 3000,
  compression: true,
  logFilePath: 'logs/server.log'
});

// Add static file middleware
app.use(new StaticFileMiddleware({
  root: 'public',
  maxAge: 86400
}).middleware());

// Add routes
app.route('/api/hello', async (req, res) => {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({ message: 'Hello World!' }));
});

// Start server
app.start().then(() => {
  console.log('Server running on port 3000');
});

Configuration

The AeroSSR constructor accepts the following configuration options:

interface AeroSSRConfig {
  port?: number;              // Default: 3000
  cacheMaxAge?: number;       // Default: 3600
  corsOrigins?: string;       // Default: '*'
  compression?: boolean;      // Default: true
  logFilePath?: string;       // Default: null
  bundleCache?: CacheStore<string>;
  templateCache?: CacheStore<string>;
  defaultMeta?: {
    title?: string;
    description?: string;
    charset?: string;
    viewport?: string;
  };
}

Static File Serving

The StaticFileMiddleware provides robust static file serving capabilities:

app.use(new StaticFileMiddleware({
  root: 'public',
  maxAge: 86400,              // 1 day cache
  index: ['index.html'],      // Default files
  dotFiles: 'ignore',         // Handle dot files
  compression: true,          // Enable compression
  etag: true                  // Enable ETags
}).middleware());

Middleware Support

AeroSSR supports middleware for request processing:

// Logging middleware
app.use(async (req, res, next) => {
  const start = Date.now();
  await next();
  console.log(`${req.method} ${req.url} - ${Date.now() - start}ms`);
});

// Error handling middleware
app.use(async (req, res, next) => {
  try {
    await next();
  } catch (error) {
    console.error(error);
    res.writeHead(500);
    res.end('Internal Server Error');
  }
});

Routing

Define routes with support for async handlers:

app.route('/api/users', async (req, res) => {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({ users: [] }));
});

Caching

Implement caching strategies using the built-in cache store:

import { createCache } from '@obinexuscomputing/aerossr';

const cache = createCache<string>();
cache.set('key', 'value');
const value = cache.get('key');

Error Handling

Custom error pages and error handling:

import { generateErrorPage } from '@obinexuscomputing/aerossr';

app.use(async (req, res, next) => {
  try {
    await next();
  } catch (error) {
    const errorPage = generateErrorPage(500, error.message);
    res.writeHead(500, { 'Content-Type': 'text/html' });
    res.end(errorPage);
  }
});

Logging

Configure custom logging:

import { Logger } from '@obinexuscomputing/aerossr';

const logger = new Logger({
  logFilePath: 'logs/custom.log'
});

Best Practices

  1. Add middleware in the correct order - logging first, then authentication, then route handlers
  2. Implement error handling middleware to catch and process errors
  3. Use caching for static files and frequently accessed data
  4. Enable compression for text-based responses
  5. Implement proper security middleware for authentication
  6. Use the built-in logger for debugging and monitoring

TypeScript Support

AeroSSR is written in TypeScript and provides comprehensive type definitions:

import type {
  RouteHandler,
  Middleware,
  StaticFileOptions,
  LoggerOptions
} from '@obinexuscomputing/aerossr';

Contributing

Please see ./docs/CONTRIBUTING.md for guidelines on contributing to AeroSSR. See the github repo and support me with buy me a coffee.

License

Support and Community

This project is licensed under the MIT License - see the LICENSE file for details.