# glob-router

> - Zero dependency - Any frontend/backend framework - Only prebuild

Latest version **0.1.6** (published 2022-12-14) · 0 weekly downloads

## Install

```sh
npm install glob-router
pnpm add glob-router
yarn add glob-router
bun add glob-router
```

Provides the command `glob-router`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2022-12-14 |
| First published | 2022-08-20 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 29.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | ymblender |

## Links

- npm: https://www.npmjs.com/package/glob-router
- Repository: https://github.com/ymzuiku/glob-router
- Homepage: git+https://github.com/ymzuiku/glob-router.git
- Issues: git+https://github.com/ymzuiku/glob-router.git
- npm.io page: https://npm.io/package/glob-router

## Dependencies (3)

- [chokidar](https://npm.io/package/chokidar.md) ^3.5.3
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.1.0
- [fast-glob](https://npm.io/package/fast-glob.md) ^3.2.11

## Recent versions

- 0.1.6 (latest) — 2022-12-14
- 0.1.5 — 2022-11-13
- 0.1.4 — 2022-09-24
- 0.1.3 — 2022-09-13
- 0.1.2 — 2022-09-11
- 0.1.1 — 2022-09-11
- 0.1.0 — 2022-08-31
- 0.0.14 — 2022-08-29
- 0.0.13 — 2022-08-28
- 0.0.12 — 2022-08-28
- 0.0.11 — 2022-08-28
- 0.0.10 — 2022-08-28
- 0.0.9 — 2022-08-27
- 0.0.8 — 2022-08-27
- 0.0.7 — 2022-08-27
- … 6 more at https://npm.io/package/glob-router/versions

## README

# 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:

```sh
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:

```tsx
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:

```tsx
/*
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:

```tsx
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:

```sh
glob-router router
```

If you need watch:

```sh
glob-router router -w
```

### If Use webpack / vite:

```js
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:

```sh
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

---
_Source: https://npm.io/package/glob-router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
