@shelter-zone/sz-express-utils
v1.0.4
Published
shelter-zone deta express utils
Downloads
19
Readme
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) {
...
}
}
)