0.1.6 • Published 1 year ago

glob-router v0.1.6

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

glob-router

  • Zero dependency
  • Any frontend/backend framework
  • Only prebuild

Use glob create client's router map and service's controller, Ignore the any framework

Your product like this:

src/
  routers/
    home/
      +page.tsx
      +serve.ts
      register
        +page.tsx
        +serve.ts
    market/
      +page.tsx
      +serve.ts
    user/
      +page.tsx
      +serve.ts
  index.ts
  serve.ts

file +page.tsx is a client's route:

export default () => {
  // any react or solid or any can use tsx / ts framework
};

file +serve.tsx is a serve's route:

Case1, use RESTFull names:

/*
Create - POST
Read - GET
Update - PATCH
Delete - DELETE
Create or update - PUT
*/

export const GET = () => {
  // do your service
};
export const POST = () => {
  // do your service
};
// export const DELETE ...
// export const PUT ...
// export const PATCH ...

Case2, use function name and .(GET|POST|PUT|PATCH|DELETE) url:

export const getTasks = () => {
  // do your service
};
// use .GET, create GET router
getTasks.GET = true;

export const getTaskDetail = () => {
  // do your service
};
getTaskDetail.GET = true;

export const addTask = () => {
  // do your service
};
addTask.POST = true;

Run glob-router

In your project run:

glob-router router

If you need watch:

glob-router router -w

If Use webpack / vite:

import globRouter from "glob-router";

const isProd = process.env.NODE_ENV === "production";
// If not production, use watch
globRouter("./src/routers", !isProd);

export default viteConfig / webpackConfig;

Effect

We can get:

router/
  /<old dirs>
  _apis.ts
  _serves.ts
  _pages.ts

That's all

  • Use pages.ts in your client's project, and use apis.ts in your fetch data
  • Use serves.ts in your nodejs service, use fastify / example or any web framework
0.1.6

1 year ago

0.1.5

1 year ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.1.4

2 years ago

0.0.5

2 years ago

0.1.3

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago