titbit-toolkit
Version:
titbit框架的工具集,包括跨域、静态资源处理,权限过滤,请求计时,cookie,session,jwt等大量中间件
59 lines (41 loc) • 869 B
JavaScript
;
class SendType {
constructor() {
}
sendType(data, type = 'html') {
this.setHeader('content-type', `${type};charset-utf-8`)
.send(data);
}
html(data) {
this.sendType(data, 'text/html')
}
json(data) {
this.sendType(data, 'application/json')
}
xml(data) {
this.sendType(data, 'application/xml')
}
text(data) {
this.sendType(data, 'text/plain')
}
js(data) {
this.sendType(data, 'text/javascript')
}
css (data) {
this.sendType(data, 'text/css')
}
mid() {
let self = this
return async (c, next) => {
c.sendType = self.sendType
c.sendhtml = self.html
c.sendjson = self.json
c.sendxml = self.xml
c.sendtext = self.text
c.sendjs = self.js
c.sendcss = self.css
await next()
}
}
}
module.exports = SendType