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

@cmmv/middleware

v0.4.8

Published

Module for simplified use of Express middlewares

Downloads

172

Readme

Description

The @cmmv/middleware module is designed to integrate Express middlewares into CMMV applications. It is based on the original implementation of Express and the features offered by the senchalabs/connect project. This module allows for flexible and modular addition of middlewares, providing a similar experience to Express. It supports a wide range of common middlewares, including authentication, session handling, request body parsing, and more, making it easy to create routes and handle HTTP requests efficiently and in an organized manner. Furthermore, the module maintains compatibility with custom middlewares, enabling developers to extend and adapt its functionality according to their application's specific needs.

Installation

Install the @cmmv/middleware package via npm:

$ pnpm add @cmmv/middleware

Quick Start

Below is a simple example of how to create a new CMMV application:

import cmmv from '@cmmv/server';
import * as cors from 'cors';
import * as compression from 'compression';
import helmet from 'helmet';
import _ from "./index";

const app = cmmv();

app.use(_(cors()));
app.use(_(helmet()));
app.use(_(compression({ level: 6, threshold: 0 })));

app.get("/", (req, res) => {
    res.json({Hello: "World"});
});

app.listen({ host: "127.0.0.1", port: 3000})
.then(server => {
    console.log(
        `Listen on http://${server.address().address}:${server.address().port}`,
    );
})
.catch(err => {
    throw Error(err.message);
});;

Middleware Compatibility Checklist

| Middleware | Status | Notes | |-------------------|--------------|---------------------------------------------------------------------------------------| | cors | ✅ Working | Middleware tested and working as expected. | | helmet | ✅ Working | Middleware tested and working as expected. | | compression | ❌ Not Working | Middleware not working due to issues with triggering onHeaders event properly. | | cookie-session | ❌ Not Working | Middleware not functioning correctly; issues with session management and Set-Cookie. | | express-session | ❌ Not Working | Middleware incompatible; issues with session handling and storage. | | serve-static | ⏳ Not Tested | Middleware for serving static files not yet tested. | | body-parser | ✅ Working | Middleware tested and working as expected. | | morgan | ✅ Working | Middleware tested and working, logs requests correctly. | | serve-favicon | ⏳ Not Tested | Middleware for serving favicons not yet tested. | | method-override | ⏳ Not Tested | Middleware for method override not yet tested. | | csurf | ⚠️ Deprecated | Middleware deprecated; not tested. | | multer | ⏳ Not Tested | Middleware for file uploads not yet tested. |

Native CMMV Middleware

CMMV provides native implementations for several common middlewares with enhanced performance optimizations. These native implementations are prefixed with @cmmv/ and include:

  • @cmmv/body-parser (NPM)
  • @cmmv/compression (NPM)
  • @cmmv/cookie-parser (NPM)
  • @cmmv/cors (NPM)
  • @cmmv/etag (NPM)
  • @cmmv/helmet (NPM)
  • @cmmv/server-static (NPM)

Summary

  • Working: cors, helmet, body-parser, and morgan have been tested and work as expected.
  • Not Working: compression, cookie-session, and express-session have issues related to header management, session handling, or storage that need to be addressed.
  • Not Tested: serve-static, serve-favicon, method-override, and multer have not been tested yet.
  • Deprecated: csurf is deprecated and will not be tested.

Summary

  • Working: cors, helmet, body-parser, morgan, serve-favicon, method-override, and multer have been tested and work as expected.
  • Not Working: compression, cookie-session, express-session, and serve-static have issues related to header management, session handling, or file serving that need to be addressed.

If you encounter issues or have suggestions on how to improve compatibility, feel free to contribute or report them on GitHub.