|
| 1 | +Object.defineProperty(exports, '__esModule', { value: true }) |
| 2 | +exports.getConfig = void 0 |
| 3 | +const fs = require('fs') |
| 4 | +const path = require('path') |
| 5 | +const YAML = require('js-yaml') |
| 6 | +const TEMPLATE_BASE_URL = 'https://serverless-templates-1300862921.cos.ap-beijing.myqcloud.com' |
| 7 | +const frameworks = { |
| 8 | + express: { |
| 9 | + injectSlsSdk: true, |
| 10 | + runtime: 'Nodejs10.15', |
| 11 | + defaultEntryFile: 'sls.js', |
| 12 | + defaultStatics: [{ src: 'public', targetDir: '/' }] |
| 13 | + }, |
| 14 | + koa: { |
| 15 | + injectSlsSdk: true, |
| 16 | + runtime: 'Nodejs10.15', |
| 17 | + defaultEntryFile: 'sls.js', |
| 18 | + defaultStatics: [{ src: 'public', targetDir: '/' }] |
| 19 | + }, |
| 20 | + egg: { |
| 21 | + injectSlsSdk: true, |
| 22 | + runtime: 'Nodejs10.15', |
| 23 | + defaultEntryFile: 'sls.js', |
| 24 | + defaultStatics: [{ src: 'public', targetDir: '/' }], |
| 25 | + defaultEnvs: [ |
| 26 | + { |
| 27 | + key: 'SERVERLESS', |
| 28 | + value: '1' |
| 29 | + }, |
| 30 | + { |
| 31 | + key: 'EGG_APP_CONFIG', |
| 32 | + value: '{"rundir":"/tmp","logger":{"dir":"/tmp"}}' |
| 33 | + } |
| 34 | + ] |
| 35 | + }, |
| 36 | + nestjs: { |
| 37 | + injectSlsSdk: true, |
| 38 | + runtime: 'Nodejs10.15', |
| 39 | + defaultEntryFile: 'sls.js', |
| 40 | + defaultStatics: [{ src: 'public', targetDir: '/' }] |
| 41 | + }, |
| 42 | + nextjs: { |
| 43 | + injectSlsSdk: true, |
| 44 | + runtime: 'Nodejs10.15', |
| 45 | + defaultEntryFile: 'sls.js', |
| 46 | + defaultStatics: [ |
| 47 | + { src: '.next/static', targetDir: '/_next/static' }, |
| 48 | + { src: 'public', targetDir: '/' } |
| 49 | + ] |
| 50 | + }, |
| 51 | + nuxtjs: { |
| 52 | + injectSlsSdk: true, |
| 53 | + runtime: 'Nodejs10.15', |
| 54 | + defaultEntryFile: 'sls.js', |
| 55 | + defaultStatics: [ |
| 56 | + { src: '.nuxt/dist/client', targetDir: '/' }, |
| 57 | + { src: 'static', targetDir: '/' } |
| 58 | + ] |
| 59 | + }, |
| 60 | + laravel: { |
| 61 | + injectSlsSdk: false, |
| 62 | + runtime: 'Php7', |
| 63 | + defaultEnvs: [ |
| 64 | + { |
| 65 | + key: 'SERVERLESS', |
| 66 | + value: '1' |
| 67 | + }, |
| 68 | + { |
| 69 | + key: 'VIEW_COMPILED_PATH', |
| 70 | + value: '/tmp/storage/framework/views' |
| 71 | + }, |
| 72 | + { |
| 73 | + key: 'SESSION_DRIVER', |
| 74 | + value: 'array' |
| 75 | + }, |
| 76 | + { |
| 77 | + key: 'LOG_CHANNEL', |
| 78 | + value: 'stderr' |
| 79 | + }, |
| 80 | + { |
| 81 | + key: 'APP_STORAGE', |
| 82 | + value: '/tmp/storage' |
| 83 | + } |
| 84 | + ] |
| 85 | + }, |
| 86 | + thinkphp: { |
| 87 | + injectSlsSdk: false, |
| 88 | + runtime: 'Php7' |
| 89 | + }, |
| 90 | + flask: { |
| 91 | + injectSlsSdk: false, |
| 92 | + runtime: 'Python3.6' |
| 93 | + }, |
| 94 | + django: { |
| 95 | + injectSlsSdk: false, |
| 96 | + runtime: 'Python3.6' |
| 97 | + } |
| 98 | +} |
1 | 99 | const CONFIGS = {
|
2 |
| - templateUrl: |
3 |
| - 'https://serverless-templates-1300862921.cos.ap-beijing.myqcloud.com/nuxtjs-demo.zip', |
4 |
| - compName: 'nuxtjs', |
5 |
| - compFullname: 'Nuxt.js', |
6 |
| - defaultEntryFile: 'sls.js', |
| 100 | + // support metrics frameworks |
| 101 | + pythonFrameworks: ['flask', 'django'], |
| 102 | + supportMetrics: ['express', 'next', 'nuxt'], |
7 | 103 | region: 'ap-guangzhou',
|
| 104 | + description: 'Created by Serverless Component', |
8 | 105 | handler: 'sl_handler.handler',
|
9 |
| - runtime: 'Nodejs10.15', |
10 |
| - timeout: 3, |
| 106 | + timeout: 10, |
11 | 107 | memorySize: 128,
|
12 | 108 | namespace: 'default',
|
13 |
| - description: 'Created by Serverless Component', |
14 |
| - defaultStatics: [ |
15 |
| - { src: '.nuxt/dist/client', targetDir: '/' }, |
16 |
| - { src: 'static', targetDir: '/' } |
| 109 | + defaultEnvs: [ |
| 110 | + { |
| 111 | + key: 'SERVERLESS', |
| 112 | + value: '1' |
| 113 | + } |
17 | 114 | ],
|
18 |
| - defaultCdnConf: { |
19 |
| - autoRefresh: true, |
| 115 | + cos: { |
| 116 | + lifecycle: [ |
| 117 | + { |
| 118 | + status: 'Enabled', |
| 119 | + id: 'deleteObject', |
| 120 | + expiration: { days: '10' }, |
| 121 | + abortIncompleteMultipartUpload: { daysAfterInitiation: '10' } |
| 122 | + } |
| 123 | + ] |
| 124 | + }, |
| 125 | + cdn: { |
| 126 | + forceRedirect: { |
| 127 | + switch: 'on', |
| 128 | + redirectType: 'https', |
| 129 | + redirectStatusCode: 301 |
| 130 | + }, |
| 131 | + https: { |
| 132 | + switch: 'on', |
| 133 | + http2: 'on' |
| 134 | + } |
| 135 | + }, |
| 136 | + defaultCdnConfig: { |
20 | 137 | forceRedirect: {
|
21 | 138 | switch: 'on',
|
22 | 139 | redirectType: 'https',
|
@@ -47,12 +164,20 @@ const CONFIGS = {
|
47 | 164 | 'name/cos:HeadObject',
|
48 | 165 | 'name/cos:OptionsObject'
|
49 | 166 | ],
|
50 |
| - Resource: [`qcs::cos:${region}:uid/${appid}:${bucket}-${appid}/*`] |
| 167 | + Resource: [`qcs::cos:${region}:uid/${appid}:${bucket}/*`] |
51 | 168 | }
|
52 | 169 | ],
|
53 | 170 | version: '2.0'
|
54 | 171 | }
|
55 | 172 | }
|
56 | 173 | }
|
57 |
| - |
58 |
| -module.exports = CONFIGS |
| 174 | +const getConfig = () => { |
| 175 | + const { name: framework } = YAML.load( |
| 176 | + // framework.yml 会在组件部署流程中动态生成 |
| 177 | + fs.readFileSync(path.join(__dirname, 'framework.yml'), 'utf-8') |
| 178 | + ) |
| 179 | + const templateUrl = `${TEMPLATE_BASE_URL}/${framework}-demo.zip` |
| 180 | + const frameworkConfigs = frameworks[framework] |
| 181 | + return Object.assign(Object.assign({ framework, templateUrl }, CONFIGS), frameworkConfigs) |
| 182 | +} |
| 183 | +exports.getConfig = getConfig |
0 commit comments