
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
fast-maker
Advanced tools
fast-maker
generate fastify.js route configuration using by directory structure.
Why fast-maker
?
fastify.js already have excellent auto route mechanics using fastify-autoload. But why you have to use fast-maker
?
fast-maker
generate TypeScript source code. Because it help to find error in compile-time, not runtime/person/[kind]-[id]/
. It help to get id and kind of id, for example serial-number and id or db-pk and id, even if you can use regular expression.fast-maker
use the same mechanics as Next.js. Route paths using file-system cannot be developer-specificfast-maker
support a beautiful cli-interfacenpx fast-maker init
npx fast-maker route
You can create configuration file using init command. And you can run route command, fast-maker
generate route.ts
file on your output directory in configuration file.
You can see this mechanics!
fast-maker
using TypeScript Compiler API. So fast-maker
exactly know handler function and route option in each file.
graph LR
A[route file] --> fast-maker
subgraph fast-maker
direction TB
C[TypeScript Compiler API]-->|extract <br/>handler function,<br /> option variable|B[fast-maker]
end
fast-maker-->|extract <br />route path|D[route.ts]
The image below briefly shows how the directory is converted to route configurations.
AS-IS (directory structure) | TO-BE (route function) | |
---|---|---|
![]() | ➜ | ![]() |
npm i fast-maker --save-dev
You can see help from --help
option.
# display help for each commands
npx fast-maker --help
# display help for route commands
npx fast-maker route --help
# display help for init commands
npx fast-maker init --help
Also you can see detail option here.
fast-maker
has a file-system based route configuration. This concept borrowed from Next.js routing system. But one difference is that HTTP Method is separated by file-system.
use file-system.
handlers/
├─ superheros/
│ ├─ [id]/
│ │ ├─ powers/
│ │ │ ├─ [id]/
│ │ │ │ ├─ delete.ts
│ │ │ │ ├─ get.ts
│ │ │ │ ├─ put.ts
│ │ │ ├─ post.ts
│ │ ├─ delete.ts
│ │ ├─ get.ts
│ │ ├─ put.ts
│ ├─ get.ts
│ ├─ post.ts
get
, post
, put
, delete
filename represent HTTP Method. Also you can use options
, patch
, head
, all
filename.
You can pass RouteShorthandOptions
option like that,
// When not using a `fastify` instance, you can declare it as a variable like this
export const option: RouteShorthandOptions = {
schema: {
querystring: schema.properties?.Querystring,
body: schema.properties?.Body,
},
};
// When using the `fastify` instance, you can declare it as a function like this
export const option = (fastify: FastifyInstance): RouteShorthandOptions => {
return {
schema: {
querystring: schema.properties?.Querystring,
body: schema.properties?.Body,
},
preHandler: fastify.auth([
fastify.allowAnonymous,
fastify.verifyBearerAuth
]),
};
};
You have to named export
and variable name must be a option
.
You can pass route handler function like that,
import { FastifyRequest } from 'fastify';
import type { IReqSearchPokemonQuerystring, IReqSearchPokemonParams } from '../../interface/IReqSearchPokemon';
export async function handler(
req: FastifyRequest<{ Querystring: IReqSearchPokemonQuerystring; Params: IReqSearchPokemonParams }>,
) {
console.debug(req.query);
console.debug(req.body);
return 'hello';
}
You have to named export
and variable name must be a handler
. Also you can use arrow function and you can use any name under TypeScript function name rule, as well as type arguments perfectly applied on route configuration
File or Directory name surrounded square bracket like that,
handlers/
├─ superheros/
│ ├─ [id]/
│ │ ├─ get.ts
│ │ ├─ put.ts
Multiple variable, No problem.
handlers/
├─ superheros/
│ ├─ [kind]-[id]/
│ │ ├─ get.ts
This route path access like that: curl http://localhost:8080/hero/marvel-ironman
That's it. fast-maker
takes care of the rest.
A complete example of using fast-maker
can be found at Ma-eum.
This software is licensed under the MIT.
FAQs
create route file on specific directory
The npm package fast-maker receives a total of 16 weekly downloads. As such, fast-maker popularity was classified as not popular.
We found that fast-maker 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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.