Skip to content

Commit

Permalink
feat(enhance): cloud function enhance less object
Browse files Browse the repository at this point in the history
add less.{lodash,assert,Buffer,url,qs,path,crypto} support
  • Loading branch information
maslow committed Mar 28, 2021
1 parent 70aa82b commit 19648ac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"express": "^4.17.1",
"fs-extra": "^9.1.0",
"less-api": "^1.3.5",
"lodash": "^4.17.21",
"log4js": "^6.3.0",
"moment": "^2.29.1",
"mongodb": "^3.6.3",
Expand Down
23 changes: 18 additions & 5 deletions src/router/function/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ async function invokeFunction(req: Request, res: Response) {
query: req.query,
body: req.body,
auth: req['auth'],
less: {
database: () => db,
storage: (namespace: string) => new LocalFileStorage(Config.LOCAL_STORAGE_ROOT_PATH, namespace),
fetch: request
}
less: createLessSdk()
})

// 函数执行耗时
Expand Down Expand Up @@ -110,4 +106,21 @@ async function invokeFunction(req: Request, res: Response) {
time_usage: debug ? time_usage : undefined,
logs: debug ? result.logs : undefined
})
}

function createLessSdk() {
const less = {
database: () => db,
storage: (namespace: string) => new LocalFileStorage(Config.LOCAL_STORAGE_ROOT_PATH, namespace),
fetch: request,
crypto: require('crypto'),
path: require('path'),
qs: require('querystring'),
url: require('url'),
Buffer: Buffer,
assert: require('assert'),
lodash: require('lodash')
}

return less
}

0 comments on commit 19648ac

Please sign in to comment.