Socket
Book a DemoInstallSign in
Socket

@astro-utils/express-endpoints

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@astro-utils/express-endpoints

Express-like framework for Astro Endpoints

2.1.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Astro Express Endpoints

Let you use an express-like framework in astro endpoints, with builtin:

Usage

const router = new ExpressRoute();

router.validate({
    body: z.object({
        name: z.string()
    })
});

export const POST = router.route(async (req, res) => {
    await new Promise(res => setTimeout(res, 1000));
    res.json({
        name: req.body.name,
        url: 'This is a POST request'
    });
});

When using the validate method it will be applied only to the next route.

Meaning that you can use the same router for multiple methods.

Body parser

The default body-parser is auto meaning that it will parse the body no matter the type of it including multipart/form-data.

You can configure the body parser by calling the body method.

const router = new ExpressRoute();

router.body('multipart');

export const POST = router.route((req, res) => {
    const myFile = req.filesOne.myFile;

    res.json({
        name: myFile?.name || 'No file',
    });
});

Use the default astro cookie parser for that

Keywords

astro

FAQs

Package last updated on 04 Apr 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.