4.1.1 • Published 3 days ago

phecda-server v4.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 days ago

phecda-server

types share between server and client, nestjs format

express

actually, it works as a set of middlewares

server side

// in test.controller.ts
import { Body, Controller, Get, Param, Post, Query, Watcher, emitter } from 'phecda-server'

@Controller('/base')
export class TestController {
  @Post('/:test')
  async test(@Param('test') test: string, @Body('name') name: string, @Query('id') id: string) {
    console.log(`${test}-${name}-${id}`)
    emitter.emit('watch', 1)
    return `${test}-${name}-${id}`
  }

  @Get('/get')
  async get() {
    return {
      data: 'test',
    }
  }
}
// in server.ts
import fs from 'fs'
import { Factory, bindApp } from 'phecda-server'
import express from 'express'
import { TestController } from './test.controller'
const data = await Factory([TestController])
fs.writeFileSync('meta.p.js', JSON.stringify(data.meta.map(item => item.data)))
const app = express()
app.all('*', (req, res, next) => {
  res.header('Access-Control-Allow-Origin', '*')
  res.header('Access-Control-Allow-Headers', 'Content-Type')
  res.header('Access-Control-Allow-Methods', '*')
  next()
})
app.use(express.json())

bindApp(app, data)

client side

// in vite.config.ts

import { defineConfig } from 'vite'
import { Server } from 'phecda-server'

export default defineConfig({
  plugins: [Server('meta.p.js')],

})
// in  main.ts

import { $S, createBeacon, createMergeReq, createReq, isError } from 'phecda-server/client'
import axios from 'axios'
import { TestController } from './test.controller'

const instance = axios.create({
  // ...
})
const useRequest = createReq(instance)
const useMergeRequest = createMergeReq(instance)
const { test, get } = new TestController()
async function request() {
  const { data } = await useRequest(test('phecda', 'server', '1'))
  console.log('[normal request]:')

  console.log(data)
}

async function seriesRequest() {
  const { data: [, res2] } = await useMergeRequest([get(), test($S(0, 'data'), 'server', '1')])
  console.log('[series request]:')

  if (isError(res2))
    console.error(res2.message)
  else console.log(res2)
}

async function mergeRequest() {
  const { data: [res1, res2] } = await useMergeRequest([test('phecda', 'server', '1'), get()])
  console.log('[merge request]:')

  if (isError(res1))
    console.error(res1.message)
  else console.log(res1)

  if (isError(res2))
    console.error(res2.message)
  else console.log(res2)
}

request()
mergeRequest()
seriesRequest()
5.0.0-beta.27

3 days ago

5.0.0-beta.26

12 days ago

5.0.0-beta.25

24 days ago

5.0.0-beta.23

1 month ago

5.0.0-beta.24

1 month ago

5.0.0-beta.22

1 month ago

5.0.0-beta.21

1 month ago

5.0.0-beta.20

1 month ago

5.0.0-beta.19

1 month ago

5.0.0-alpha.18

1 month ago

5.0.0-alpha.17

1 month ago

5.0.0-alpha.16

2 months ago

5.0.0-alpha.15

2 months ago

5.0.0-alpha.14

2 months ago

5.0.0-alpha.13

2 months ago

5.0.0-alpha.12

2 months ago

5.0.0-alpha.11

2 months ago

5.0.0-alpha.10

2 months ago

5.0.0-alpha.9

2 months ago

5.0.0-alpha.8

3 months ago

5.0.0-alpha.7

3 months ago

5.0.0-alpha.6

3 months ago

5.0.0-alpha.5

3 months ago

5.0.0-alpha.4

3 months ago

4.1.2-alpha.1

4 months ago

4.1.2-alpha.3

4 months ago

4.1.2-alpha.2

4 months ago

4.1.2-alpha.0

4 months ago

4.1.1

4 months ago

4.1.0

4 months ago

4.0.7

4 months ago

4.0.6

4 months ago

4.0.5

4 months ago

4.0.4

4 months ago

4.0.3

4 months ago

4.0.2

4 months ago

4.0.1

4 months ago

4.0.0

5 months ago

4.0.0-alpha.11

5 months ago

4.0.0-alpha.10

5 months ago

4.0.0-alpha.9

5 months ago

4.0.0-alpha.8

5 months ago

4.0.0-alpha.7

5 months ago

4.0.0-alpha.6

5 months ago

3.2.0-alpha.4

5 months ago

3.2.0-alpha.5

5 months ago

3.2.0-alpha.0

6 months ago

3.2.0-alpha.1

6 months ago

3.2.0-alpha.2

5 months ago

3.2.0-alpha.3

5 months ago

3.0.3

6 months ago

3.0.2

6 months ago

3.1.0

6 months ago

3.0.1

6 months ago

3.0.0

7 months ago

3.0.0-alpha.7

7 months ago

3.0.0-alpha.6

8 months ago

3.0.0-alpha.1

8 months ago

3.0.0-alpha.3

8 months ago

3.0.0-alpha.2

8 months ago

3.0.0-alpha.5

8 months ago

3.0.0-alpha.4

8 months ago

1.5.1

12 months ago

1.5.0

12 months ago

1.4.1

12 months ago

1.4.0

12 months ago

2.1.2

9 months ago

2.0.3

10 months ago

2.1.1

9 months ago

2.0.2

10 months ago

2.1.4

8 months ago

3.0.0-alpha.0

8 months ago

2.1.3

9 months ago

2.1.0

10 months ago

2.0.1

11 months ago

2.0.0

11 months ago

1.3.0

12 months ago

1.2.4

12 months ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago