Skip to content

SHELTER-ZONE/sz-express-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sz-express-utils

middleware

sendResponse

import express from 'express'
import { sendResponse } from '@shelter-zone/sz-express-utils'

const app = express()
app.use(sendResponse)

middleware/validate

useReqDataValidate

import { useReqDataValidate } from '@shelter-zone/sz-express-utils'
import { CreateUserDataValidate } from './model'

const { joiValidate, superStructValidate } = useReqDataValidate()

router.post(
  '/user',
  joiValidate(CreateUserDataValidate, 'body'),
  async (req, res) => {...}
)

useApiAuthentication

import { useApiAuthentication } from '@shelter-zone/sz-express-utils'
import { userDB } from './db'
import routes from './routes'

const PRIVATEKEY = process.env.PRIVATEKEY

const userAuthentication = useApiAuthentication(userDB, PRIVATEKEY)

export const router = express.Router()
router.use('/api', userAuthentication, routes)

logger

import { log } from '@shelter-zone/sz-express-utils'
log({
  level: 'info',
  message: 'hello world',
})

Utils

validateUserID

import { validateUserID } from '@shelter-zone/sz-express-utils'

router.post(
  '/user',
  async (req, res) => {
    try {
      await validateUserID(req.headers.authorization, req.body.id)
      ...
    }
    catch (err) {
      ...
    }
  }
)

About

[📦 npm package] sz express.js utils package

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published