Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cmmv/cookie-parser

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cmmv/cookie-parser

CMMV (@cookie-parser)

  • 0.6.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
328
increased by137.68%
Maintainers
0
Weekly downloads
 
Created
Source

CMMV Logo

Contract-Model-Model-View (CMMV)
Building scalable and modular applications using contracts.

NPM Version Package License CircleCI

DocumentationReport Issue

Description

@cmmv/server is inspired by the popular Express.js framework but has been entirely rewritten in TypeScript with performance improvements in mind. The project integrates common plugins like body-parser, compression, cookie-parser, cors, etag, helmet and serve-static out of the box. Additionally, it plans to support any Express.js-compatible plugin in the near future.

Installation

Install the @cmmv/server package via npm:

$ pnpm add @cmmv/server

Quick Start

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

//import { readFileSync } from "node:fs";

import cmmv, { json, urlencoded, serverStatic } from '@cmmv/server';
import etag from '@cmmv/etag';
import cors from '@cmmv/cors';
import cookieParser from '@cmmv/cookie-parser';
import compression from '@cmmv/compression';
import helmet from '@cmmv/helmet';

const app = cmmv({
    /*http2: true,
    https: {
        key: readFileSync("./cert/private-key.pem"),
        cert: readFileSync("./cert/certificate.pem"),
        passphrase: "1234"
    }*/
});

const host = '0.0.0.0';
const port = 3000;

app.use(serverStatic('public'));
app.use(cors());
app.use(etag({ algorithm: 'fnv1a' }));
app.use(cookieParser());
app.use(json({ limit: '50mb' }));
app.use(urlencoded({ limit: '50mb', extended: true }));
app.use(compression({ level: 6 }));
app.use(
    helmet({
        contentSecurityPolicy: {
            useDefaults: false,
            directives: {
                defaultSrc: ["'self'"],
                scriptSrc: ["'self'", 'example.com'],
                objectSrc: ["'none'"],
                upgradeInsecureRequests: [],
            },
        },
    }),
);

app.set('view engine', 'pug');

app.get('/view', async (req, res) => {
    res.render('index', { title: 'Hey', message: 'Hello there!' });
});

app.get('/', async (req, res) => {
    res.send('Hello World');
});

app.get('/json', async (req, res) => {
    const schema = {
        type: 'object',
        properties: {
            hello: {
                type: 'string'
            }
        }
    }
    
    res.json({ hello: 'world' }, schema);
});

app.get('/user/:id', async (req, res) => {
    res.send('User ' + req.params.id);
});

app.get('/users', async (req, res) => {
    res.json(req.query);
});

app.post('/test', async (req, res) => {
    console.log(req.body);
    res.send('ok');
});

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

Features

  • Performance Optimized: Faster and more efficient with improvements over Express.js.
  • Built-in Plugins: Includes commonly used middleware like compression, body-parser, cookie-parser, and more.
  • TypeScript First: Fully written in TypeScript for better type safety and developer experience.
  • Express.js Compatibility: Plans to support Express.js-compatible plugins.
  • HTTP/2 Support: Native support for HTTP/2, improving speed and connection performance.

Benchmarks

  • https://github.com/fastify/benchmarks
  • Machine: linux x64 | 32 vCPUs | 256.6GB Mem
  • Node: v20.17.0
  • Run: Thu Oct 02 2024 15:23:41 GMT+0000 (Coordinated Universal Time)
  • Method: autocannon -c 100 -d 40 -p 10 localhost:3000
VersionRouterRequests/sLatency (ms)Throughput/Mb
barev20.17.045270.421.628.07
micro10.0.144705.821.937.97
fastify5.0.044547.822.017.99
connect3.7.044174.422.187.88
polka0.5.243791.222.377.81
rayo1.4.643731.822.417.80
server-base-router7.1.3243117.622.727.69
server-base7.1.3242169.423.247.52
micro-route2.5.041600.023.557.42
connect-router1.3.841163.323.857.34
cmmv0.4.040995.223.927.35
hono4.6.339738.624.687.09
polkadot1.0.037472.826.206.68
koa2.15.337181.426.426.63
0http3.5.337101.626.476.62
take-five2.0.035171.427.9512.65
h31.13.034667.428.356.18
koa-isomorphic-router1.0.134542.728.466.16
h3-router1.13.033551.029.315.98
restana4.9.933532.829.365.98
koa-router12.0.133426.229.465.96
microrouter3.1.330049.232.795.36
hapi21.3.1030014.832.825.35
restify11.1.028548.034.555.15
fastify-big-json5.0.011675.685.19134.34
express5.0.110058.298.821.79
express-with-middlewares5.0.18826.8112.633.28
trpc-router10.45.2N/AN/AN/A

Keywords

FAQs

Package last updated on 27 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc