
Security News
RubyGems Adds Cooldown Feature to Bundler for Newly Published Gems
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.
Luren是基于Koa一个简单web框架,可以快速方便的生成RESTFUL风格的API,提供依赖注入InversifyJS和RESTFUL API的文档Swagger的支持.Luren是基于Decorator来设置Controller的,所以ts中必须开启decorator支持。Luren在启动时会自动加载工作目录下的boot, middleware,controllers,models四个目录下的ts/js文件。
src
├── boot
├── controllers
├── middlewares
├── models
Controller提供API的组件,也是Luren中最重要的一个组件,一个controller即代表一个资源,controller中包含多个action,即资源相关的API。下面的controller会生成一个POST /api/v1/demos/foo的API, 当接受请求时会检查相应的参数,如header,query,body等然后处理之后传递给相应的action函数,在action函数返回结果之后,会将结果根据Response类型进行处理然后返回。
@injectable()
@Controller({ prefix: '/api', version: 'v1' })
export default class DemoController {
@Action({ method: HttpMethod.POST, path: '/foo' })
@Response({ type: 'string' })
public async foo( @InBody('name','string', true) name: string) {
return `Hello ${name}`
}
Middleware是一个普通函数或者继承Processor或实现IProcessor接口的对象
async function handle(ctx: Context, next: INext) {
// do something
await next()
}
class Authorization extends Processor<boolean> {
public async process(@InQuery('name') name: string) {
return name === 'foo'
}
}
通过luren-schema对model类进行注解,可在其他地方直接引用该类型, 同时可以链接到相应的DataSource。
@Collection({datasource: 'mongodb', database: 'demo' })
@Schema()
export default class User {
@Prop()
public firstName: string
@Prop()
public lastName: string
@Prop({type: 'number', required: true})
public age: number
}
boot文件下包含需要随应用一起启动的内容, 文件以文件名的顺序加载。
Luren支持使用InversifyJS来加载controller
@injectable()
@Controller({ prefix: '/api', version: 'v1' })
export default class DemoController {
@Action({ path: '/foo' })
@Response({ type: Person })
public async bar(@InQuery('name') name: string) {
return null
}
// create server with inversify container
const server = new Luren({ container })
luren-swagger可以作为插件加载,会根据controller的注解自动生成Swagger文档。
const server = new Luren({ container })
const swagger = new Swagger({
info: { title: 'demo', version: '1.0' },
servers: [{ url: '/', description: 'demo api' }]
})
server.plugin(swagger.pluginify())
import jwt from 'jsonwebtoken'
import _ from 'lodash'
import { APITokenAuthentication, Luren } from 'luren'
import { Swagger } from 'luren-swagger'
import dataSource from './dataSource'
import container from './inversify'
// create server with inversify container
const server = new Luren({ container })
// set work directory
server.setWorkDirectory(__dirname)
// set data source
server.setDefaultDataSource(dataSource)
// authentication
server.setDefaultAuthentication(
new APITokenAuthentication({
key: 'Authorization',
source: 'header',
async validate(accessToken: string) {
const data = jwt.verify(accessToken, 'jwt-key')
return data ? true : false
}
})
)
// serve files
server.serve('/public', { root: '/', maxage: 30 * 24 * 60 * 60 * 1000, defer: true })
// setup swagger plugin
const swagger = new Swagger({
info: { title: 'demo', version: '1.0' },
servers: [{ url: '/', description: 'demo api' }]
})
server.plugin(swagger.pluginify())
// start server
server.listen(3000).then(async () => {
logger.info('Server started')
}er.info('Server started')
})
FAQs
Luren is a simple framework based on Koa2
We found that luren demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.