1 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
2 | import 'reflect-metadata'
|
3 | import {Container} from 'inversify'
|
4 | import {getConnectionManager, Connection, BaseEntity, getRepository, SelectQueryBuilder} from '@bxjs/typeorm'
|
5 | import {xsession, xuser, xcache} from './session'
|
6 | import * as $$ from './plugins'
|
7 |
|
8 | const path = require('path')
|
9 | const ErrorStackParser = require('error-stack-parser')
|
10 | const cookie = require('cookie')
|
11 | const MobileDetect = require('mobile-detect')
|
12 | const fetch = require('node-fetch')
|
13 | const _ = require('lodash')
|
14 | const moment = require('moment')
|
15 | const extend = require('extend')
|
16 | const querystring = require('querystring')
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | const circular_json = require("circular-json")
|
26 | const mockjs = require('mockjs')
|
27 | const shortid = require('shortid')
|
28 | const validatorjs = require('validatorjs')
|
29 | const cross_spawn = require('cross-spawn')
|
30 | const ACMClient = require('acm-client')
|
31 | const co = require('co')
|
32 |
|
33 |
|
34 | const raw_stringify = JSON.stringify
|
35 |
|
36 | function new_stringify(value: any, replacer?: (key: string, value: any) => any,
|
37 | space?: string | number): string {
|
38 | let out = raw_stringify(value, replacer, space)
|
39 | if (_.isString(out)) {
|
40 | out = out.replace(/\\n/g, '\\\\n')
|
41 | .replace(/\\t/g, '\\\\t')
|
42 | .replace(/\\u/g, '\\\\u')
|
43 | }
|
44 | return out
|
45 | }
|
46 |
|
47 | JSON.stringify = new_stringify as any
|
48 |
|
49 |
|
50 | export function get_suffix_ts_or_js() {
|
51 | if (global['__env__'] == 'local' && !/^\/code\/node_modules/.test(__dirname)) {
|
52 | return 'ts'
|
53 | } else {
|
54 | return 'js'
|
55 | }
|
56 | }
|
57 |
|
58 |
|
59 | function __get_base_func_caller_source_position(position: number = 3) {
|
60 | try {
|
61 | throw new Error()
|
62 | } catch (err) {
|
63 | let out = ErrorStackParser.parse(err)
|
64 | let idx = 0
|
65 |
|
66 | let find_ts_sufix_file_count = 0
|
67 | for (; idx < out.length; idx++) {
|
68 | if (/\.ts$/.test(out[idx].fileName)) {
|
69 | find_ts_sufix_file_count += 1
|
70 | }
|
71 | if (find_ts_sufix_file_count == position) {
|
72 | break
|
73 | }
|
74 | }
|
75 | if (find_ts_sufix_file_count == position) {
|
76 | return '[' + out[idx]['fileName'] + ':' + out[idx]['lineNumber'] + ']'
|
77 | } else {
|
78 |
|
79 |
|
80 | console.error(circular_json.stringify(out, null, 4)
|
81 | .replace(/\r/g, '').replace(/\n/g, ''))
|
82 | return '#'
|
83 | }
|
84 |
|
85 | }
|
86 | }
|
87 |
|
88 |
|
89 | export function xstack(err, compact = true) {
|
90 | try {
|
91 |
|
92 | let stack = ErrorStackParser.parse(err)
|
93 | if (compact) {
|
94 | let sources: string[] = []
|
95 | for (let v of stack) {
|
96 | sources.push(`${v['fileName']}:${v['lineNumber']}`)
|
97 | }
|
98 | return sources
|
99 | }
|
100 | return stack
|
101 | } catch (err1) {
|
102 | let source = __get_base_func_caller_source_position()
|
103 | return `invalid error input param (${source})`
|
104 | }
|
105 | }
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | export function xerror(err, __param?: any) {
|
119 | xassert(err instanceof Error)
|
120 | try {
|
121 |
|
122 | let data: any = JSON.parse(err.message)
|
123 | if (data.code && data.msg && ERRORS[data.code]) {
|
124 | return data
|
125 | }
|
126 | } catch (err) {
|
127 |
|
128 | }
|
129 |
|
130 | let msg = ERRORS[ERR$UNKNOWN]['zh']
|
131 | let code = ERR$UNKNOWN
|
132 | let param: any = {msg: err.message, param: __param}
|
133 | let stack = xstack(err)
|
134 | let data = {msg, code, param, stack}
|
135 | return data
|
136 | }
|
137 |
|
138 |
|
139 | export function xroot(err: Error) {
|
140 | xassert(err instanceof Error)
|
141 | let {msg, param, code, stack} = xerror(err)
|
142 |
|
143 |
|
144 | for (; param && param.msg;) {
|
145 | try {
|
146 | let json: any = JSON.parse(param.msg)
|
147 | param = json.param
|
148 | } catch (err) {
|
149 | msg = param.msg
|
150 | code = param.code
|
151 | stack = param.stack
|
152 | param = param.param
|
153 | break
|
154 | }
|
155 | }
|
156 | return {msg, code, param, stack}
|
157 | }
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 | export function xthrow(code: string | Error = ERR$UNKNOWN, param: any = undefined, reject_param: any = undefined) {
|
173 |
|
174 | let reject: any = _.isFunction(param) ? param : undefined
|
175 | if (reject) param = reject_param
|
176 | let data: any = {}
|
177 | let source = __get_base_func_caller_source_position()
|
178 |
|
179 | if (code instanceof Error) {
|
180 | try {
|
181 | data = JSON.parse(code.message)
|
182 |
|
183 | if (!_.isArray(data.stack)) {
|
184 | data.stack = []
|
185 | }
|
186 | data.stack.push(source)
|
187 | } catch (err) {
|
188 |
|
189 | }
|
190 |
|
191 | if (data.code && data.msg && ERRORS[data.code]) {
|
192 |
|
193 | if (_.isFunction(reject)) {
|
194 |
|
195 | let err = new Error(JSON.stringify(data))
|
196 | reject(err)
|
197 | return
|
198 | } else {
|
199 | throw new Error(JSON.stringify(data))
|
200 | }
|
201 | }
|
202 |
|
203 | data = xerror(code, param)
|
204 | data.code = ERR$UNKNOWN
|
205 | data.msg = ERRORS[ERR$UNKNOWN]['zh']
|
206 | data.param = {msg: code.message, param, stack: [source]}
|
207 | } else {
|
208 |
|
209 | data = {code, msg: global['ERRORS'][code as string]['zh'], param, stack: [source]}
|
210 | }
|
211 |
|
212 |
|
213 | if (_.isFunction(reject)) {
|
214 |
|
215 | reject(new Error(JSON.stringify(data)))
|
216 | } else {
|
217 |
|
218 | throw new Error(JSON.stringify(data))
|
219 | }
|
220 | }
|
221 |
|
222 | export function xassert(expr: any, code: string = ERR$ASSERT, param?: any) {
|
223 | let source = __get_base_func_caller_source_position()
|
224 | let stack = [source]
|
225 | if (!expr) throw new Error(JSON.stringify({code, msg: global['ERRORS'][code]['zh'], param, stack}))
|
226 | return expr
|
227 | }
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 | export function xlog(...args) {
|
241 |
|
242 | let source = __get_base_func_caller_source_position()
|
243 | let output = circular_json.stringify([...args], null, 4)
|
244 | if (global['__env__'] != 'prod' && !/^\/code\/node_modules/.test(__dirname)) {
|
245 |
|
246 | console.log.apply(undefined, [source + output])
|
247 |
|
248 | const fs = require('fs')
|
249 | const logFilePath = process.env['NODE_LOGFILE'] ? process.env['NODE_LOGFILE'] : '/tmp/bxjs.log'
|
250 | fs.appendFileSync(logFilePath, source + output + "\r\n")
|
251 | } else {
|
252 |
|
253 | output = output.replace(/\r/g, '').replace(/\n/g, '')
|
254 | console.log.apply(undefined, [source + output])
|
255 | }
|
256 | }
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 | async function xwarn(...args) {
|
269 |
|
270 | let source = __get_base_func_caller_source_position()
|
271 |
|
272 |
|
273 | if (args.length > 0 && args[0] instanceof Error) {
|
274 | args[0] = xerror(args[0])
|
275 | }
|
276 |
|
277 | let out = [source, moment().format('YYYY-MM-DD HH:mm:ss'), {...args}]
|
278 |
|
279 |
|
280 | let access_token = xconfig('framework.warn.dingding.access_token')
|
281 | let mobiles = xconfig('framework.warn.dingding.mobiles')
|
282 | if (!access_token || !mobiles) {
|
283 | access_token = '020a09eac5f2fa320ae851442d5e19e23693c64ad2255c85354b4a49a5a48d35'
|
284 | mobiles = ['15381151346']
|
285 | }
|
286 |
|
287 | await xpost(`https://oapi.dingtalk.com/robot/send?access_token=${access_token}`, {
|
288 | msgtype: 'text',
|
289 | text: {
|
290 | content: out
|
291 | },
|
292 | at: {
|
293 | atMobiles: mobiles,
|
294 | isAtAll: false
|
295 | }
|
296 | })
|
297 |
|
298 |
|
299 |
|
300 | xlog(out)
|
301 | }
|
302 |
|
303 |
|
304 | process.on('uncaughtException', async function (err) {
|
305 | xlog(xerror(err))
|
306 | await xwarn(err)
|
307 | process.exit(-1)
|
308 | })
|
309 |
|
310 |
|
311 | process.on('unhandledRejection', async (reason, p) => {
|
312 | xlog('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
313 |
|
314 | await xwarn(reason, p)
|
315 | process.exit(-1)
|
316 | })
|
317 |
|
318 |
|
319 | const sleep = require('sleep-async')()
|
320 |
|
321 | export function xsleep(ms: number = -1) {
|
322 | if (ms <= 0) {
|
323 | ms = 50 * 365 * 24 * 3600 * 1000
|
324 | }
|
325 | return new Promise((resolve, reject) => {
|
326 | try {
|
327 | sleep.sleep(ms, () => {
|
328 | resolve()
|
329 | })
|
330 | } catch (err) {
|
331 | xlog(xerror(err))
|
332 | resolve()
|
333 |
|
334 | }
|
335 | })
|
336 | }
|
337 |
|
338 | export async function xpost(url: string, param?: { [propName: string]: any },
|
339 | headers?: { [propName: string]: any }, timeout: number = 3000) {
|
340 |
|
341 | timeout = 5000
|
342 | let res: any = null
|
343 | let json: any = null
|
344 | let text: any = null
|
345 | try {
|
346 | res = await fetch(url, {
|
347 | method: 'POST',
|
348 | body: JSON.stringify(param),
|
349 | headers: {'Content-Type': 'application/json', ...headers},
|
350 | timeout: timeout <= 0 ? 0 : timeout,
|
351 | })
|
352 | text = await res.text()
|
353 | json = JSON.parse(text)
|
354 | return json
|
355 | } catch (err) {
|
356 | xthrow(err, {url, param, headers, text})
|
357 | }
|
358 | }
|
359 |
|
360 |
|
361 | export async function xget(url: string, param?: { [propName: string]: any },
|
362 | headers?: { [propName: string]: any }, timeout: number = 3000) {
|
363 |
|
364 | timeout = 5000
|
365 | let res: any = null
|
366 | let json: any = null
|
367 | let text: any = null
|
368 | try {
|
369 | url = url + (param ? '?' : '') + querystring.stringify(param)
|
370 | res = await fetch(url, {
|
371 | method: 'GET',
|
372 | headers: {'Content-Type': 'application/json', ...headers},
|
373 | timeout: timeout <= 0 ? 0 : timeout,
|
374 | })
|
375 | text = await res.text()
|
376 | json = JSON.parse(text)
|
377 | return json
|
378 | } catch (err) {
|
379 | xthrow(err, {url, param, headers, text})
|
380 | }
|
381 | }
|
382 |
|
383 |
|
384 | export function xredirect(url: string, param: any = {}) {
|
385 |
|
386 |
|
387 | xassert(global['__redirect_url__'] === undefined)
|
388 | if (param) {
|
389 | xassert(_.isPlainObject(param))
|
390 |
|
391 | delete param.__api__
|
392 | delete param.__url__
|
393 |
|
394 | if (/\?/.test(url)) {
|
395 | url += '&'
|
396 | } else {
|
397 | url += '?'
|
398 | }
|
399 | url += querystring.stringify(param)
|
400 | }
|
401 | global['__redirect_url__'] = url
|
402 | }
|
403 |
|
404 |
|
405 | export function xcookie(key?: string, value?: string, option?: {}): any {
|
406 | if (!arguments.length) {
|
407 |
|
408 | return global['__request_cookies__'] ? global['__request_cookies__'] : {}
|
409 | } else if (arguments.length == 1) {
|
410 | return key ? xcookie()[key] : undefined
|
411 | } else {
|
412 | if (global['__respond_cookies__'] === undefined) {
|
413 | global['__respond_cookies__'] = {}
|
414 | }
|
415 | if (key) {
|
416 |
|
417 | option = xassign({path: '/', maxAge: 24 * 3600}, option)
|
418 | global['__respond_cookies__'][key] = cookie.serialize(key, value, option)
|
419 | }
|
420 | return
|
421 | }
|
422 | }
|
423 |
|
424 |
|
425 | function xismobile(): boolean {
|
426 | const md = new MobileDetect(global['__user_agent__'])
|
427 | return !!md.mobile()
|
428 | }
|
429 |
|
430 | function xassign(target, source, ...args) {
|
431 | const param = [true, target, source, ...args]
|
432 | return extend.apply(null, param)
|
433 | }
|
434 |
|
435 |
|
436 | function xconfig(path: string, defaultValue: any = undefined) {
|
437 | if (global['__config__']) {
|
438 | return _.get(global['__config__'], path, defaultValue)
|
439 | }
|
440 |
|
441 | const fp = require('path')
|
442 | const fs = require('fs')
|
443 |
|
444 | let config_path = ''
|
445 | if (__dirname.includes('/node_modules/@bxjs/base/')) {
|
446 |
|
447 | config_path = fp.join(__dirname, '../../../../app/config')
|
448 | } else {
|
449 |
|
450 | config_path = fp.join(__dirname, '../app/config')
|
451 | }
|
452 |
|
453 |
|
454 | const config_base_path = config_path + '/config.base.' + get_suffix_ts_or_js()
|
455 | const config_env_path = config_path + `/config.${global['__env__']}.` + get_suffix_ts_or_js()
|
456 | if (!fs.existsSync(config_base_path)) {
|
457 | return defaultValue
|
458 | }
|
459 | let config_base = require(config_base_path).default
|
460 | let config_env = {}
|
461 | if (fs.existsSync(config_env_path)) {
|
462 | config_env = require(config_env_path).default
|
463 | }
|
464 |
|
465 |
|
466 |
|
467 | global['__config__'] = xassign({}, config_base, config_env)
|
468 | return _.get(global['__config__'], path, defaultValue)
|
469 | }
|
470 |
|
471 | async function xconnect(callback: (connect: Connection) => Promise<any>, config = 'default') {
|
472 | return new Promise(async (resolve, reject) => {
|
473 | let cfg = {} as any
|
474 | try {
|
475 | cfg = xassign({}, xconfig('plugins.database.default', {}))
|
476 | xassert(!_.isEmpty(cfg), ERR$PARAM, {config})
|
477 |
|
478 | if (__dirname.includes('/node_modules/@bxjs/base/')) {
|
479 |
|
480 | cfg['entities'] = [
|
481 | path.join(__dirname, '../../../../app/plugins/database/entity/*.' + get_suffix_ts_or_js())
|
482 | ]
|
483 | } else {
|
484 |
|
485 | cfg['entities'] = [
|
486 | path.join(__dirname, '../app/plugins/database/entity/*.' + get_suffix_ts_or_js())
|
487 | ]
|
488 | }
|
489 |
|
490 | const mng = getConnectionManager()
|
491 | const name = cfg.name ? cfg.name : 'default'
|
492 | if (!mng.has(name)) {
|
493 | mng.create(cfg)
|
494 | }
|
495 | const db = mng.get(name)
|
496 | if (global['__connection__'] === undefined) {
|
497 | global['__connection__'] = {}
|
498 | }
|
499 | if (!db.isConnected) {
|
500 | global['__connection__'][name] = db.connect()
|
501 | }
|
502 | await global['__connection__'][name].then(async connection => {
|
503 | xassert(db.isConnected)
|
504 | const out = await callback(connection)
|
505 |
|
506 | resolve(out)
|
507 | }).catch(async err => {
|
508 |
|
509 | xthrow(err, reject, {cfg})
|
510 | })
|
511 | } catch (err) {
|
512 | xthrow(err, reject, {cfg})
|
513 | }
|
514 | })
|
515 | }
|
516 |
|
517 |
|
518 | function xnew<T extends BaseEntity>(TYPE: new () => T, param?: any, ...args): T {
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 | let obj = new TYPE()
|
525 | if (_.isEmpty(param)) {
|
526 | return obj
|
527 | }
|
528 | let repo = getRepository<T>(TYPE)
|
529 | repo.merge.apply(repo, [obj, param, ...args])
|
530 | return obj
|
531 | }
|
532 |
|
533 |
|
534 | function xquery<T>(connect: Connection, TYPE: new () => T, alias?: string): SelectQueryBuilder<T> {
|
535 | return connect.getRepository(TYPE).createQueryBuilder(alias)
|
536 | }
|
537 |
|
538 |
|
539 | async function xcount<T>(sql: SelectQueryBuilder<T>, page: number, size: number): Promise<[any[] | null, number]> {
|
540 | xassert(page >= 1)
|
541 | const [count, rows] = await Promise.all([
|
542 | sql.getCount(),
|
543 | sql.offset((page - 1) * size).limit(size).getRawMany()
|
544 | ])
|
545 | return [rows, count]
|
546 | }
|
547 |
|
548 |
|
549 |
|
550 |
|
551 | function xroute(param: { name?: string, desc?: string, path?: string, auth?: boolean }) {
|
552 |
|
553 | param = xassign({name: '', desc: '', path: '', auth: true}, param)
|
554 | return function (target: Function, propertyKey: string, descriptor: PropertyDescriptor) {
|
555 |
|
556 |
|
557 | target.prototype.context = () => {
|
558 | return {
|
559 | param: param,
|
560 |
|
561 | auth: async () => {
|
562 |
|
563 | if (param && param.auth) {
|
564 |
|
565 |
|
566 | const auth = xgot(YAuth)
|
567 | xassert(await auth.getLoginStatus(), ERR$UNAUTHORIZED)
|
568 | }
|
569 | }
|
570 | }
|
571 | }
|
572 | }
|
573 | }
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 | function xmock<T>(rules: T): any {
|
590 | return mockjs.mock(rules)
|
591 | }
|
592 |
|
593 | function xrandom(name: string, data: any[]) {
|
594 | mockjs.Random.extend({
|
595 | [name]: (...args) => {
|
596 | xassert(data.length > 0)
|
597 | if (data.length == 1) return data[0]
|
598 | let max = data.length - 1
|
599 | let idx = xmock(`@int(0,${max})`)
|
600 | return data[idx]
|
601 | }
|
602 | })
|
603 | }
|
604 |
|
605 |
|
606 | mockjs.Random.extend({
|
607 |
|
608 | id: (...args) => {
|
609 | return shortid.generate()
|
610 | },
|
611 |
|
612 | mobile: (...args) => {
|
613 | const isps = [
|
614 | 134, 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, 178,
|
615 | 130, 131, 132, 145, 155, 156, 185, 186, 176,
|
616 | 133, 134, 153, 180, 181, 189, 177, 173,
|
617 | 176, 173, 177, 178, 170,
|
618 | 140, 141, 142, 143, 144, 146, 148, 149, 154]
|
619 | let max = isps.length - 1
|
620 | let idx = xmock(`@int(0,${max})`)
|
621 | let num = xmock(`@int(100000000,199999999)`)
|
622 | return (isps[idx] * 100000000 + num % 100000000) + ''
|
623 | },
|
624 |
|
625 | paragraph: (...args) => {
|
626 | switch (args.length) {
|
627 | case 0:
|
628 | return xmock('@cparagraph')
|
629 | case 1:
|
630 | return xmock(`@cparagraph(${args[0]})`)
|
631 | case 2:
|
632 | return xmock(`@cparagraph(${args[0]},${args[1]})`)
|
633 | default:
|
634 | xassert(false)
|
635 | }
|
636 |
|
637 | },
|
638 | sentence: (...args) => {
|
639 | switch (args.length) {
|
640 | case 0:
|
641 | return xmock('@csentence')
|
642 | case 1:
|
643 | return xmock(`@csentence(${args[0]})`)
|
644 | case 2:
|
645 | return xmock(`@csentence(${args[0]},${args[1]})`)
|
646 | default:
|
647 | xassert(false)
|
648 | }
|
649 |
|
650 | },
|
651 | title: (...args) => {
|
652 | switch (args.length) {
|
653 | case 0:
|
654 | return xmock('@ctitle')
|
655 | case 1:
|
656 | return xmock(`@ctitle(${args[0]})`)
|
657 | case 2:
|
658 | return xmock(`@ctitle(${args[0]},${args[1]})`)
|
659 | default:
|
660 | xassert(false)
|
661 | }
|
662 |
|
663 | },
|
664 | })
|
665 |
|
666 |
|
667 | function xcheck<T>(param: T, rules: T, messages?: Object) {
|
668 | let obj = new validatorjs(param, rules)
|
669 | if (obj.fails()) {
|
670 | xthrow(ERR$PARAM, obj.errors)
|
671 | }
|
672 | }
|
673 |
|
674 |
|
675 | function xbind<T>(TYPE: new () => T) {
|
676 | const o: any = new TYPE()
|
677 | return xcontainer.bind<T>(o.id).to(require(`@app/plugins/${o.id}`).default)
|
678 | }
|
679 |
|
680 |
|
681 | function xgot<T>(TYPE: new () => T) {
|
682 | const o: any = new TYPE()
|
683 | return xcontainer.get<T>(o.id)
|
684 | }
|
685 |
|
686 |
|
687 | async function xcmd(...args: string[]): Promise<any> {
|
688 | try {
|
689 | const options: any = {}
|
690 | options.cwd = options.cwd || process.env.__ctxPath || process.cwd();
|
691 | xassert(_.isArray(args) && args.length > 0)
|
692 | const cmd = args.shift()
|
693 | const ret = cross_spawn.sync(cmd, args, xassign({stdio: 'inherit'}, options))
|
694 | xassert(ret.status === 0, ERR$UNKNOWN, ret)
|
695 | return ret
|
696 | } catch (err) {
|
697 | await xwarn(err)
|
698 | xthrow(err)
|
699 | }
|
700 | }
|
701 |
|
702 |
|
703 | async function xmap<T>(values: T[], callack: (v: T) => Promise<any>): Promise<any[]> {
|
704 | xassert(_.isArray(values) && _.isFunction(callack))
|
705 | return Promise.all(values.map(callack))
|
706 | }
|
707 |
|
708 |
|
709 |
|
710 | async function xacm(group: string, id: string) {
|
711 | const cfg = xconfig(`plugins.acm`)
|
712 | xassert(cfg && cfg[group], ERR$CONFIG, {cfg})
|
713 | const acm = new ACMClient(cfg[group])
|
714 | return new Promise(async (resolve, reject) => {
|
715 | try {
|
716 | co(function* () {
|
717 | try {
|
718 | const content = yield acm.getConfig(id, group)
|
719 | xassert(content, ERR$CONFIG)
|
720 | resolve(content)
|
721 | } catch (err) {
|
722 | xthrow(err, reject, {id, group, cfg: cfg[group]})
|
723 | }
|
724 | });
|
725 | } catch (err) {
|
726 | xthrow(err, reject, {id, group, cfg: cfg[group]})
|
727 | }
|
728 | })
|
729 | }
|
730 |
|
731 | if (!global['__env__']) {
|
732 | global['__env__'] = 'local'
|
733 | }
|
734 | global['__config__'] = undefined
|
735 | global['__session__'] = {}
|
736 | global['__cache__'] = {}
|
737 | global['__user__'] = {}
|
738 | global['__user_agent__'] = undefined
|
739 | global['__client_ip__'] = undefined
|
740 | global['__redirect_url__'] = undefined
|
741 | global['__request_cookies__'] = {}
|
742 | global['__respond_cookies__'] = {}
|
743 |
|
744 | global['xconnect'] = xconnect
|
745 | global['xnew'] = xnew
|
746 | global['xquery'] = xquery
|
747 | global['xcount'] = xcount
|
748 | global['xassign'] = xassign
|
749 | global['xconfig'] = xconfig
|
750 | global['xthrow'] = xthrow
|
751 | global['xassert'] = xassert
|
752 | global['xerror'] = xerror
|
753 | global['xroot'] = xroot
|
754 | global['xstack'] = xstack
|
755 | global['xwarn'] = xwarn
|
756 | global['xlog'] = xlog
|
757 | global['xpost'] = xpost
|
758 | global['xget'] = xget
|
759 | global['xsleep'] = xsleep
|
760 | global['xredirect'] = xredirect
|
761 | global['xcookie'] = xcookie
|
762 | global['xismobile'] = xismobile
|
763 | global['xsession'] = xsession
|
764 | global['xuser'] = xuser
|
765 | global['xcache'] = xcache
|
766 | global['xroute'] = xroute
|
767 | global['xmock'] = xmock
|
768 | global['xrandom'] = xrandom
|
769 | global['xcheck'] = xcheck
|
770 | global['xcontainer'] = new Container()
|
771 | global['xbind'] = xbind
|
772 | global['xgot'] = xgot
|
773 | global['YAuth'] = $$.YAuth
|
774 | global['xcmd'] = xcmd
|
775 | global['xmap'] = xmap
|
776 | global['xacm'] = xacm
|