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

@mikosoft/spa-server

v2.0.2

Published

Single Page Application (SPA) HTTP server with a proxy server to boost the website SEO.

Downloads

45

Readme

@mikosoft/spa-server

HTTP server for serving single page applications (dodo, angular, vue, react, svelte, etc).

This Node.js HTTP server is designed to serve Single Page Applications (SPAs) efficiently. It handles various types of static files and provides server-side rendering (SSR) capabilities based on configuration options.

Installation

$ npm install --save @mikosoft/spa-server

Features

  • very fast & simple to use
  • Static File Serving: Serves static files like HTML, CSS, JavaScript, images, fonts, etc., from a specified directory (staticDir).
  • Index File Handling: Serves a default index.html file when the URL does not contain a file extension.
  • URL Rewrite: Maps specific URLs to different directories based on configurable rules (urlRewrite).
  • Server-Side Rendering (SSR): Optionally modifies HTML content on the server before serving, useful for SEO or initial page rendering (ssr).
  • Compression: Supports gzip and deflate compression for optimizing data transfer.
  • Customizable Response Headers: Allows customization of HTTP response headers, including CORS headers.
  • Timeout Handling: Automatically handles request timeouts to prevent hanging connections.
  • Debugging: Provides optional debug logs to track server activity and HTML content.

HTTP Server

Serve single page application on the HTTP server.

import { HTTPServer } from '@mikosoft/spa-server';

const httpOpts = {
  staticDir: 'dist',
  indexFile: 'index.html',
  urlRewrite: {}, // map URLs to directory: {url1: dir1, url2:dir2} NOTICE:The url i.e. the object key can contain regex chars like ^ $ * ...
  port: process.env.PORT || 3000,
  timeout: 5 * 60 * 1000, // if 0 never timeout
  acceptEncoding: 'gzip', // gzip, deflate or ''
  headers: {
    // CORS Response Headers
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept, Authorization',
    'Access-Control-Allow-Methods': 'OPTIONS, GET',
    'Access-Control-Max-Age': '3600'
  },
  ssr: 'all', // none, all, botsonly
  ssrConsole: false, // frontend JS logs in the backend
  ssrModifier: (document) => { // modify document on the server side
    document.title = 'Modified title';
    const script = document.createElement('script');
    script.textContent = "console.log('Dynamic script executed!')";
    document.body.appendChild(script);
  },
  debug: false,
  debugHTML: true
};
const httpServer = new HTTPServer(httpOpts);
httpServer.start();

OPTIONS (httpOpts)

  • staticDir:string, - directory with static, frontend files (path relative to process.cwd())
  • indexFile:string, - root HTML file (in the staticDir)
  • urlRewrite:object, - map URLs to directory: {url1: dir1, url2:dir2} NOTICE:The url i.e. the object key can contain regex chars like ^ $ * ...
  • port:number - HTTP Server port number
  • timeout:number - ms to wait for response. If 0 then the HTTP connection will never close. Default is 5 minute
  • acceptEncoding:string - gzip or deflate
  • headers:object - custom server response headers
  • ssr:'all'|'botsonly'|'none' - server side rendering
  • ssrConsole:boolean - show frontend JS logs on the backend terminal
  • ssrModifier:null|Function - modify document on the server side
  • debug:boolean - print debug messages
  • debugHTML:boolean - debug initial and postrender HTML

HTTP Server methods

  • start() - start the HTTP server
  • stop() - stop the HTTP server
  • restart() - restart the HTTP server

Events

listening: Event emitted when the HTTP server starts listening for connections. close: Event emitted when the HTTP server closes. error: Event emitted when an error occurs in the HTTP server.

Contributing

Feel free to contribute by submitting issues and pull requests on GitHub.

Support

Contact on www.mikosoft.info

Licence

Copyright (C) 2023-present MikoSoft licensed under MIT .