
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@phila/philaroute
Advanced tools
Basic HTTP router for AWS API Gateway / Proxy Lambdas with composable pipelines built with TypeScript.
A lightweight, composable HTTP router for Node.js Lambda/API Gateway environments, written in TypeScript. Supports composable middleware pipelines and CORS out of the box.
npm install philaroute
Philaroute revolves around the usage of pipelines to composably and easily manage different routes and controllers. Parsing and response are built in. Effectively, you need to supply an array of functions that utilize the following type:
export type RestAccumulator = {
request?: {
params?: {
[key: string]: string
},
body?: any,
headers?: {
[key: string]: string
},
mvHeaders?: {
[key: string]: string[]
},
}
data?: {
[key: string]: any
},
response: {
statusCode?: number,
headers?: {
[key: string]: string
},
isBase64Encoded?: boolean,
body?: string | Record<string, any> | any[]
}
};
type RestPipelineFn = (acc: RestAccumulator): Promise<RestAccumulator>
import { Router, http } from 'philaroute';
const { HttpStatus } = http;
const router = Router({ cors: { 'Access-Control-Allow-Origin': '*' } });
const world = router.path('/hello');
world.get([
http.set({
body: 'Hello World!'
})
]);
// In your Lambda handler:
export const main = async (event) => {
return router.routeToPath(event);
};
Advanced pipeline example
import { validate } from './validate';
import { opensearch } from './opensearch';
const router = Router();
const page = router.path('page')
page.get([
validate.pageName,
validate.userToken,
opensearch.search(['search, vector']), // does relevant logic to search two different collections in paralle, puts data into acc.data.
opensearch.rank, // ranks search results, applies to acc.response.body
// Can use http.set to customize response; otherwise acc.response.body will be preferentially returned, acc.data otherwise.
]);
---
## CORS
CORS headers can be set globally when creating the router or updated later:
```typescript
const worldRouter = router({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,OPTIONS',
});
npm run build
npm test
npm run lint
npm run format
MIT © City of Philadelphia
For more information, see the Official Project Documentation.
FAQs
Basic HTTP router for AWS API Gateway / Proxy Lambdas with composable pipelines built with TypeScript.
The npm package @phila/philaroute receives a total of 0 weekly downloads. As such, @phila/philaroute popularity was classified as not popular.
We found that @phila/philaroute demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers 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 Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.