
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
astro-router
Advanced tools
At the time of writing, Astro SSR does not yet support Middleware. This project is just a simple router that adds middleware to your Astro SSR projects, as well as some utilities like getting params, query params, headers, etc.
At the time of writing, Astro SSR does not yet support Middleware. This project is just a simple router that adds middleware to your Astro SSR projects, as well as some utilities like getting params, query params, headers, etc.
npm i -S astro-router
Import the router
:
import { router } from 'astro-router';
Then export your get
, post
, etc:
/foo/[...all]/index.js
:
export const get = router({
routes: [
{
path: '/foo',
response: () => new Response(null, {status: 200})
}
]
});
/sales/[...all]/index.js
:
import { router } from 'astro-router';
import { auth, logger } from './middleware.js';
import { User, Order } from './db.js';
export const get = router({
routes: [
{
path: '/sales/:user/:order',
middleware: [logger, auth],
response({params}) {
const user = await User.findOne({id: params.user});
const order = await Order.findOne({id: params.order});
return new Response(null, {status: 200});
}
}
]
})
Request: /users/1234?foo=bar
:
export const get = router({
path: '/users/:id',
middleware: [logger, auth],
response: ({params, query}) => {
console.log(params.id) // '1234'
console.log(query.foo) // 'bar'
}
});
export const get = router({
/** Routes */
routes: [
{
/** The path to match, supports 'express'-style route params */
path: '/users/:id',
middleware: [
({
/** Astro's original `request` object */
request,
/** Any query params as object */
query,
/** Route params as object */
params,
/** Headers as object */
headers
/** Url object */
url,
/** Next middleware to invoke */
next
}) => {
next();
}
],
response: ({
/** Astro's original `request` object */
request,
/** Any query params as object */
query,
/** Route params as object */
params,
/** Headers as object */
headers
/** Url object */
url,
}) => {
return new Response(null, {status: 200})
}
}
],
/**
* Custom fallback in case no routes match
* defaults to a 404 response
*/
fallback: () => new Response(null, {status: 404}),
})
FAQs
At the time of writing, Astro SSR does not yet support Middleware. This project is just a simple router that adds middleware to your Astro SSR projects, as well as some utilities like getting params, query params, headers, etc.
The npm package astro-router receives a total of 6 weekly downloads. As such, astro-router popularity was classified as not popular.
We found that astro-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.