New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

obyek

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

obyek

web framework

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

const {route}=require("obyek")
class App extends route("/"){
  constructor(){
    super()
    this.listen(3000)
  }
  get(req,res){
    res.send("Hello world")
  }
}
new App()

this is a rather opinionated framework. but maybe it can't be called opinionated nor can it be called unopinionated. that's because some libraries for doing things that are usually installed separately are available by default. using the OOP paradigm to make grouping easier and more

installation

npm i obyek

usage

hello world

const {route}=require("obyek")
class App extends route("/"){
  constructor(){
    super()
    this.listen(3000)
  }
  get(req,res){
    res.send("Hello world")
  }
}
new App()
add child route
const {route}=require("obyek")

class Foo extends route("/foo"){
  get(req,res){
    res.send("Foo")
  }
}

class Bar extends route("/bar") {
  get(req,res) {
    res.send("Bar")
  }
}
class App extends route("/") {
  constructor() {
    super()
    this.childRoute(new Foo())
    .childRoute(new Bar())
    .listen(3000)
  }
  get(req,res) {
    res.send("Hello world")
  }
}
new App()
add middleware
const {route}=require("obyek")
class App extends route("/") {
  constructor() {
    super()
    
    
    //relative to current route path
    this.app.all("/",(req,res,next)=>{
      console.info("all")
      next()
    })
    
    
    this.app.post("/",(req,res,next)=>{
      console.info("post")
      next()
    })
    this.listen(3000)
    
  }
  get(req,res) {
    res.send("Hello world")
  }
  post(req,res){
    res.json(req.body)
  }
}
new App()
logger
const {logger}=require("obyek")
//winston
logger.info("hello")
config
const {route,config}=require("obyek")

//default
config({
  logDirName:"log",
  notFoundMiddleware:(req,res)=>{
  res.status(404)
    res.json({
      status:"error",
      message:"not found",
      error:{
        detail:`cannot ${req.method} ${req.url}`
      }
    })
  },
  errorMiddleware:(err,req,res,next)=>{
        console.error(err)
        res.status(500)
        res.json({status:"error",message:"internal server error",
        error:{detail:err.stack}})
  }
})

class App extends route("/"){
  get(){
    throw new Error("error")
  }


  //config method is called after listen method
  config(cnfg){
        //default
        //set to false to disable middleware
        cnfg.json={}
        cnfg.cors = false //{}
        cnfg.helmet=false //{}
        cnfg.compression=false //{}
        cnfg.urlencoded={
          extended:false
        }
        cnfg.cookieParser=[] //[secret,options]
        cnfg.static = false //[root,options]
        
   }
}

new App().listen(3000)
unit test
const {route,testRequest} = require("obyek")

class App extends route("/"){
  get(req,res){
    res.send("testing")
  }
}

//i assume you are using jest
test("example test",async ()=>{
  expect((
  await testRequest(new App())
  .get("/")
  ).text).toBe("testing")
})

Contributing

The obyek project welcomes all constructive contributions. Contributions take many forms, from code for bug fixes and enhancements, to additions and fixes to documentation, additional tests, triaging incoming pull requests and issues

Keywords

http

FAQs

Package last updated on 24 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts