├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ ├── release.yml │ ├── test.yml │ └── validate.yml ├── .gitignore ├── .npmignore ├── .npmrc ├── .prettierignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── __tests__ ├── index.test.js └── lib │ └── utils.js ├── commitlint.config.js ├── docs ├── configure.md └── upload.md ├── example ├── .editorconfig ├── .env.example ├── .gitattributes ├── .gitignore ├── .styleci.yml ├── app │ ├── Console │ │ └── Kernel.php │ ├── Exceptions │ │ └── Handler.php │ ├── Http │ │ ├── Controllers │ │ │ └── Controller.php │ │ ├── Kernel.php │ │ └── Middleware │ │ │ ├── Authenticate.php │ │ │ ├── CheckForMaintenanceMode.php │ │ │ ├── EncryptCookies.php │ │ │ ├── RedirectIfAuthenticated.php │ │ │ ├── TrimStrings.php │ │ │ ├── TrustHosts.php │ │ │ ├── TrustProxies.php │ │ │ └── VerifyCsrfToken.php │ ├── Providers │ │ ├── AppServiceProvider.php │ │ ├── AuthServiceProvider.php │ │ ├── BroadcastServiceProvider.php │ │ ├── EventServiceProvider.php │ │ └── RouteServiceProvider.php │ └── User.php ├── artisan ├── bootstrap │ ├── app.php │ └── cache │ │ └── .gitignore ├── composer.json ├── composer.lock ├── config │ ├── app.php │ ├── auth.php │ ├── broadcasting.php │ ├── cache.php │ ├── cors.php │ ├── database.php │ ├── filesystems.php │ ├── hashing.php │ ├── logging.php │ ├── mail.php │ ├── queue.php │ ├── services.php │ ├── session.php │ └── view.php ├── database │ ├── .gitignore │ ├── factories │ │ └── UserFactory.php │ ├── migrations │ │ ├── 2014_10_12_000000_create_users_table.php │ │ └── 2019_08_19_000000_create_failed_jobs_table.php │ └── seeds │ │ └── DatabaseSeeder.php ├── package.json ├── phpunit.xml ├── public │ ├── .htaccess │ ├── favicon.ico │ ├── index.php │ ├── robots.txt │ └── web.config ├── resources │ ├── js │ │ ├── app.js │ │ └── bootstrap.js │ ├── lang │ │ └── en │ │ │ ├── auth.php │ │ │ ├── pagination.php │ │ │ ├── passwords.php │ │ │ └── validation.php │ ├── sass │ │ └── app.scss │ └── views │ │ └── welcome.blade.php ├── routes │ ├── api.php │ ├── channels.php │ ├── console.php │ └── web.php ├── server.php ├── serverless.yml └── webpack.mix.js ├── jest.config.js ├── package.json ├── prettier.config.js ├── release.config.js ├── serverless.component.yml └── src ├── _shims └── sl_handler.php ├── config.js ├── package.json ├── serverless.js └── utils.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | end_of_line = lf 9 | insert_final_newline = true 10 | indent_size = 2 11 | indent_style = space 12 | trim_trailing_whitespace = true 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | coverage 2 | dist 3 | node_modules 4 | example 5 | *.test.js -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: ['prettier'], 4 | plugins: ['import', 'prettier'], 5 | env: { 6 | es6: true, 7 | jest: true, 8 | node: true 9 | }, 10 | parser: 'babel-eslint', 11 | parserOptions: { 12 | ecmaVersion: 2018, 13 | sourceType: 'module', 14 | ecmaFeatures: { 15 | jsx: true 16 | } 17 | }, 18 | globals: { 19 | on: true // for the Socket file 20 | }, 21 | rules: { 22 | 'array-bracket-spacing': [ 23 | 'error', 24 | 'never', 25 | { 26 | objectsInArrays: false, 27 | arraysInArrays: false 28 | } 29 | ], 30 | 'arrow-parens': ['error', 'always'], 31 | 'arrow-spacing': ['error', { before: true, after: true }], 32 | 'comma-dangle': ['error', 'never'], 33 | curly: 'error', 34 | 'eol-last': 'error', 35 | 'func-names': 'off', 36 | 'id-length': [ 37 | 'error', 38 | { 39 | min: 1, 40 | max: 50, 41 | properties: 'never', 42 | exceptions: ['e', 'i', 'n', 't', 'x', 'y', 'z', '_', '$'] 43 | } 44 | ], 45 | 'no-alert': 'error', 46 | 'no-console': 'off', 47 | 'no-const-assign': 'error', 48 | 'no-else-return': 'error', 49 | 'no-empty': 'off', 50 | 'no-shadow': 'error', 51 | 'no-undef': 'error', 52 | 'no-unused-vars': 'error', 53 | 'no-use-before-define': 'error', 54 | 'no-useless-constructor': 'error', 55 | 'object-curly-newline': 'off', 56 | 'object-shorthand': 'off', 57 | 'prefer-const': 'error', 58 | 'prefer-destructuring': ['error', { object: true, array: false }], 59 | quotes: [ 60 | 'error', 61 | 'single', 62 | { 63 | allowTemplateLiterals: true, 64 | avoidEscape: true 65 | } 66 | ], 67 | semi: ['error', 'never'], 68 | 'spaced-comment': 'error', 69 | strict: ['error', 'global'], 70 | 'prettier/prettier': 'error' 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | 7 | jobs: 8 | release: 9 | name: Release 10 | runs-on: ubuntu-latest 11 | env: 12 | GH_TOKEN: ${{ secrets.GH_TOKEN }} 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v2 16 | with: 17 | persist-credentials: false 18 | 19 | - name: Install Node.js and npm 20 | uses: actions/setup-node@v1 21 | with: 22 | node-version: 14.x 23 | registry-url: https://registry.npmjs.org 24 | 25 | - name: Retrieve dependencies from cache 26 | id: cacheNpm 27 | uses: actions/cache@v2 28 | with: 29 | path: | 30 | ~/.npm 31 | node_modules 32 | key: npm-v14-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }} 33 | restore-keys: npm-v14-${{ runner.os }}-refs/heads/master- 34 | 35 | - name: Install dependencies 36 | if: steps.cacheNpm.outputs.cache-hit != 'true' 37 | run: | 38 | npm update --no-save 39 | npm update --save-dev --no-save 40 | - name: Releasing 41 | run: | 42 | npm run release 43 | env: 44 | GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} 45 | GIT_AUTHOR_NAME: slsplus 46 | GIT_AUTHOR_EMAIL: slsplus.sz@gmail.com 47 | GIT_COMMITTER_NAME: slsplus 48 | GIT_COMMITTER_EMAIL: slsplus.sz@gmail.com 49 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | pull_request: 5 | branches: [master] 6 | 7 | jobs: 8 | test: 9 | name: Test 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout repository 13 | uses: actions/checkout@v2 14 | with: 15 | # Ensure connection with 'master' branch 16 | fetch-depth: 2 17 | 18 | - name: Install Node.js and npm 19 | uses: actions/setup-node@v1 20 | with: 21 | node-version: 14.x 22 | registry-url: https://registry.npmjs.org 23 | 24 | - name: Retrieve dependencies from cache 25 | id: cacheNpm 26 | uses: actions/cache@v2 27 | with: 28 | path: | 29 | ~/.npm 30 | node_modules 31 | key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} 32 | restore-keys: | 33 | npm-v14-${{ runner.os }}-${{ github.ref }}- 34 | npm-v14-${{ runner.os }}-refs/heads/master- 35 | 36 | - name: Install dependencies 37 | if: steps.cacheNpm.outputs.cache-hit != 'true' 38 | run: | 39 | npm update --no-save 40 | npm update --save-dev --no-save 41 | - name: Running tests 42 | run: npm run test 43 | env: 44 | SERVERLESS_PLATFORM_VENDOR: tencent 45 | GLOBAL_ACCELERATOR_NA: true 46 | TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }} 47 | TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }} 48 | -------------------------------------------------------------------------------- /.github/workflows/validate.yml: -------------------------------------------------------------------------------- 1 | name: Validate 2 | 3 | on: 4 | pull_request: 5 | branches: [master] 6 | 7 | jobs: 8 | lintAndFormatting: 9 | name: Lint & Formatting 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout repository 13 | uses: actions/checkout@v2 14 | with: 15 | # Ensure connection with 'master' branch 16 | fetch-depth: 2 17 | 18 | - name: Install Node.js and npm 19 | uses: actions/setup-node@v1 20 | with: 21 | node-version: 14.x 22 | registry-url: https://registry.npmjs.org 23 | 24 | - name: Retrieve dependencies from cache 25 | id: cacheNpm 26 | uses: actions/cache@v2 27 | with: 28 | path: | 29 | ~/.npm 30 | node_modules 31 | key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} 32 | restore-keys: | 33 | npm-v14-${{ runner.os }}-${{ github.ref }}- 34 | npm-v14-${{ runner.os }}-refs/heads/master- 35 | 36 | - name: Install dependencies 37 | if: steps.cacheNpm.outputs.cache-hit != 'true' 38 | run: | 39 | npm update --no-save 40 | npm update --save-dev --no-save 41 | 42 | - name: Validate Formatting 43 | run: npm run prettier:fix 44 | - name: Validate Lint rules 45 | run: npm run lint:fix 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.sublime-project 3 | *.sublime-workspace 4 | *.log 5 | .serverless 6 | v8-compile-cache-* 7 | jest/* 8 | coverage 9 | .serverless_plugins 10 | testProjects/*/package-lock.json 11 | testProjects/*/yarn.lock 12 | .serverlessUnzipped 13 | node_modules 14 | .vscode/ 15 | .eslintcache 16 | dist 17 | .idea 18 | build/ 19 | .env* 20 | env.js 21 | package-lock.json 22 | test 23 | yarn.lock -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test 2 | example -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.sublime-project 3 | *.sublime-workspace 4 | *.log 5 | .serverless 6 | v8-compile-cache-* 7 | jest/* 8 | coverage 9 | .serverless_plugins 10 | testProjects/*/package-lock.json 11 | testProjects/*/yarn.lock 12 | .serverlessUnzipped 13 | node_modules 14 | .vscode/ 15 | .eslintcache 16 | dist 17 | .idea 18 | build/ 19 | .env* 20 | env.js 21 | package-lock.json 22 | yarn.lock 23 | example 24 | CHANGELOG.md 25 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [0.2.1](https://github.com/serverless-components/tencent-laravel/compare/v0.2.0...v0.2.1) (2021-02-23) 2 | 3 | 4 | ### Bug Fixes 5 | 6 | * support base64 encode ([db98f6b](https://github.com/serverless-components/tencent-laravel/commit/db98f6ba368fabe898d42020b153eb88e9f30efd)) 7 | 8 | # [0.2.0](https://github.com/serverless-components/tencent-laravel/compare/v0.1.2...v0.2.0) (2021-02-23) 9 | 10 | 11 | ### Features 12 | 13 | * support post form data ([ea1af31](https://github.com/serverless-components/tencent-laravel/commit/ea1af31739596d818b99d7206c84180662dd24da)) 14 | 15 | ## [0.1.2](https://github.com/serverless-components/tencent-laravel/compare/v0.1.1...v0.1.2) (2020-12-15) 16 | 17 | 18 | ### Bug Fixes 19 | 20 | * update deploy and remove flow ([#19](https://github.com/serverless-components/tencent-laravel/issues/19)) ([7bd779a](https://github.com/serverless-components/tencent-laravel/commit/7bd779af406ecb863160b6272ff2bb6395167364)) 21 | 22 | ## [0.1.1](https://github.com/serverless-components/tencent-laravel/compare/v0.1.0...v0.1.1) (2020-12-04) 23 | 24 | 25 | ### Bug Fixes 26 | 27 | * update prepare inputs method ([#18](https://github.com/serverless-components/tencent-laravel/issues/18)) ([4d940f7](https://github.com/serverless-components/tencent-laravel/commit/4d940f7f9c4ed6716fe31a65fc374f632cd7bb95)) 28 | 29 | # [0.1.0](https://github.com/serverless-components/tencent-laravel/compare/v0.0.8...v0.1.0) (2020-12-04) 30 | 31 | 32 | ### Bug Fixes 33 | 34 | * update deps ([82d8696](https://github.com/serverless-components/tencent-laravel/commit/82d8696e0b4446414f81cd398646b4f9410d602c)) 35 | 36 | 37 | ### Features 38 | 39 | * support no migration deploy ([9670f55](https://github.com/serverless-components/tencent-laravel/commit/9670f55e521b15886297b99d8d89d5fe10a90cac)) 40 | 41 | ## [0.0.8](https://github.com/serverless-components/tencent-laravel/compare/v0.0.7...v0.0.8) (2020-09-07) 42 | 43 | 44 | ### Bug Fixes 45 | 46 | * update deploy flow for multi region ([b63c58e](https://github.com/serverless-components/tencent-laravel/commit/b63c58e6ba06597cd18dee4e963404f28b062ba3)) 47 | 48 | ## [0.0.7](https://github.com/serverless-components/tencent-laravel/compare/v0.0.6...v0.0.7) (2020-09-04) 49 | 50 | 51 | ### Bug Fixes 52 | 53 | * update deps ([665a6cd](https://github.com/serverless-components/tencent-laravel/commit/665a6cde0b0bf5df90b5d84eafa28ff9e37339aa)) 54 | 55 | ## [0.0.6](https://github.com/serverless-components/tencent-laravel/compare/v0.0.5...v0.0.6) (2020-09-02) 56 | 57 | 58 | ### Bug Fixes 59 | 60 | * support cfs config ([1af615b](https://github.com/serverless-components/tencent-laravel/commit/1af615bf4bf6950c862387b25f414f8d14cc1fbe)) 61 | * update tencnet-component-toolkit for api mark ([b5de551](https://github.com/serverless-components/tencent-laravel/commit/b5de551fe3fcddfc7021f01f7b0563c0b2cc9669)) 62 | 63 | ## [0.0.5](https://github.com/serverless-components/tencent-laravel/compare/v0.0.4...v0.0.5) (2020-08-26) 64 | 65 | 66 | ### Bug Fixes 67 | 68 | * apigw isDisabled ([c27183d](https://github.com/serverless-components/tencent-laravel/commit/c27183d7ec1b420c5a16dcd03185bb72c0413f7c)) 69 | * prettier config ([3e06493](https://github.com/serverless-components/tencent-laravel/commit/3e06493fbf9c99f9e293f2f851884cd0a5315577)) 70 | * support eip config ([0a18bc0](https://github.com/serverless-components/tencent-laravel/commit/0a18bc0e12e2422806c9eab3edfc2ffa064ae4c1)) 71 | * support fonts type binary ([242dc08](https://github.com/serverless-components/tencent-laravel/commit/242dc080162f93c27aa8f94adc67db307269ecb2)) 72 | * traffic zero display bug ([63e53eb](https://github.com/serverless-components/tencent-laravel/commit/63e53eb393dab71f9b38fdd627910f947a865ca5)) 73 | * update get credential error message ([6cd73f0](https://github.com/serverless-components/tencent-laravel/commit/6cd73f0e78dd6ab5e95d721cc0dbc82d2d01fdc8)) 74 | * upgrade deps ([4880ca3](https://github.com/serverless-components/tencent-laravel/commit/4880ca396d8dc4673504e189c900f971c83a357a)) 75 | * upgrade deps ([7bc2f9e](https://github.com/serverless-components/tencent-laravel/commit/7bc2f9e076d2ab02cf0bddc8180666844cf3ecf3)) 76 | * upgrade deps ([c9166b7](https://github.com/serverless-components/tencent-laravel/commit/c9166b7733e769175aed9103c2aeeab923ba3e85)) 77 | 78 | 79 | ### Features 80 | 81 | * support scf publish version and traffic setup ([947b2f7](https://github.com/serverless-components/tencent-laravel/commit/947b2f7f16b82fc9aca3b5e822a6b00041f77586)) 82 | * support usage plan & auth ([a41c2b5](https://github.com/serverless-components/tencent-laravel/commit/a41c2b591400e814e2b1826b2d100f92d8f75e04)) 83 | * upgrade laravel to v2 ([77574f9](https://github.com/serverless-components/tencent-laravel/commit/77574f9de9ba70391f0729087dd82846ae01facd)) 84 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Tencent Cloud, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ⚠️⚠️⚠️ 所有框架组件项目迁移到 [tencent-framework-components](https://github.com/serverless-components/tencent-framework-components). 2 | 3 | [![Serverless PHP Laravel Tencent Cloud](https://img.serverlesscloud.cn/20191226/1577347087676-website_%E9%95%BF.png)](http://serverless.com) 4 | 5 | [![Build Status](https://github.com/serverless-components/tencent-laravel/workflows/Test/badge.svg)](https://github.com/serverless-components/tencent-laravel/actions?query=workflow:Test) 6 | 7 |
8 | 9 | 腾讯云 [Laravel](https://github.com/laravel/laravel) Serverless Component, 支持 `Laravel >= 6.0`。 10 | 11 |
12 | 13 | 特性介绍: 14 | 15 | - [x] **按需付费** - 按照请求的使用量进行收费,没有请求时无需付费 16 | - [x] **"0"配置** - 只需要关心项目代码,之后部署即可,Serverless Framework 会搞定所有配置。 17 | - [x] **极速部署** - 仅需几秒,部署你的整个 laravel 应用。 18 | - [x] **便捷协作** - 通过云端的状态信息和部署日志,方便的进行多人协作开发。 19 | - [x] **自定义域名** - 支持配置自定义域名及 HTTPS 访问 20 | 21 |
22 | 23 | 快速开始: 24 | 25 | 1. [**安装**](#1-安装) 26 | 2. [**创建**](#2-创建) 27 | 3. [**部署**](#3-部署) 28 | 4. [**配置**](#4-配置) 29 | 5. [**查看状态**](#5-查看状态) 30 | 6. [**移除**](#6-移除) 31 | 32 | 更多资源: 33 | 34 | - [**架构说明**](#架构说明) 35 | - [**账号配置**](#账号配置) 36 | 37 |   38 | 39 | ### 1. 安装 40 | 41 | 通过 npm 安装最新版本的 Serverless Framework 42 | 43 | ```bash 44 | $ npm install -g serverless 45 | ``` 46 | 47 | ### 2. 创建 48 | 49 | 通过如下命令和模板链接,快速创建一个 laravel 应用: 50 | 51 | ```bash 52 | $ serverless init laravel-starter --name serverless-laravel 53 | $ cd example 54 | ``` 55 | 56 | ### 3. 部署 57 | 58 | 在 `serverless.yml` 文件所在的项目根目录,运行以下指令进行部署: 59 | 60 | ```bash 61 | $ serverless deploy 62 | ``` 63 | 64 | 部署时需要进行身份验证,如您的账号未 [登陆](https://cloud.tencent.com/login) 或 [注册](https://cloud.tencent.com/register) 腾讯云,您可以直接通过 `微信` 扫描命令行中的二维码进行授权登陆和注册。 65 | 66 | > 注意: 如果希望查看更多部署过程的信息,可以通过`serverless deploy --debug` 命令查看部署过程中的实时日志信息。 67 | 68 | ### 4. 配置 69 | 70 | laravel 组件支持 0 配置部署,也就是可以直接通过配置文件中的默认值进行部署。但你依然可以修改更多可选配置来进一步开发该 laravel 项目。 71 | 72 | 以下是 laravel 组件的 `serverless.yml`配置示例: 73 | 74 | ```yml 75 | # serverless.yml 76 | 77 | app: appDemo 78 | stage: dev 79 | 80 | component: laravel 81 | name: laravelDemo 82 | 83 | inputs: 84 | src: 85 | src: ./ 86 | functionName: laravelDemo 87 | region: ap-guangzhou 88 | runtime: Php7 89 | apigatewayConf: 90 | protocols: 91 | - http 92 | - https 93 | environment: release 94 | ``` 95 | 96 | 点此查看[全量配置及配置说明](https://github.com/serverless-components/tencent-laravel/tree/master/docs/configure.md) 97 | 98 | 当你根据该配置文件更新配置字段后,再次运行 `serverless deploy` 或者 `serverless` 就可以更新配置到云端。 99 | 100 | ### 5. 查看状态 101 | 102 | 在`serverless.yml`文件所在的目录下,通过如下命令查看部署状态: 103 | 104 | ``` 105 | $ serverless info 106 | ``` 107 | 108 | ### 6. 移除 109 | 110 | 在`serverless.yml`文件所在的目录下,通过以下命令移除部署的 laravel 服务。移除后该组件会对应删除云上部署时所创建的所有相关资源。 111 | 112 | ``` 113 | $ serverless remove 114 | ``` 115 | 116 | 和部署类似,支持通过 `serverless remove --debug` 命令查看移除过程中的实时日志信息。 117 | 118 | ## 架构说明 119 | 120 | laravel 组件将在腾讯云账户中使用到如下 Serverless 服务: 121 | 122 | - [x] **API 网关** - API 网关将会接收外部请求并且转发到 SCF 云函数中。 123 | - [x] **SCF 云函数** - 云函数将承载 laravel.js 应用。 124 | - [x] **CAM 访问控制** - 该组件会创建默认 CAM 角色用于授权访问关联资源。 125 | - [x] **COS 对象存储** - 为确保上传速度和质量,云函数压缩并上传代码时,会默认将代码包存储在特定命名的 COS 桶中。 126 | - [x] **SSL 证书服务** - 如果你在 yaml 文件中配置了 `apigatewayConf.customDomains` 字段,需要做自定义域名绑定并开启 HTTPS 时,也会用到证书管理服务和域名服务。Serverless Framework 会根据已经备案的域名自动申请并配置 SSL 证书。 127 | 128 | ## 账号配置 129 | 130 | 当前默认支持 CLI 扫描二维码登录,如您希望配置持久的环境变量/秘钥信息,也可以本地创建 `.env` 文件 131 | 132 | ```console 133 | $ touch .env # 腾讯云的配置信息 134 | ``` 135 | 136 | 在 `.env` 文件中配置腾讯云的 SecretId 和 SecretKey 信息并保存 137 | 138 | 如果没有腾讯云账号,可以在此[注册新账号](https://cloud.tencent.com/register)。 139 | 140 | 如果已有腾讯云账号,可以在[API 密钥管理](https://console.cloud.tencent.com/cam/capi)中获取 `SecretId` 和`SecretKey`. 141 | 142 | ``` 143 | # .env 144 | TENCENT_SECRET_ID=123 145 | TENCENT_SECRET_KEY=123 146 | ``` 147 | 148 | ## License 149 | 150 | MIT License 151 | 152 | Copyright (c) 2020 Tencent Cloud, Inc. 153 | -------------------------------------------------------------------------------- /__tests__/index.test.js: -------------------------------------------------------------------------------- 1 | const { generateId, getServerlessSdk } = require('./lib/utils') 2 | const axios = require('axios') 3 | 4 | const instanceYaml = { 5 | org: 'orgDemo', 6 | app: 'appDemo', 7 | component: 'laravel@dev', 8 | name: `laravel-integration-tests-${generateId()}`, 9 | stage: 'dev', 10 | inputs: { 11 | runtime: 'Php7', 12 | region: 'ap-guangzhou', 13 | apigatewayConf: { environment: 'test' } 14 | } 15 | } 16 | 17 | const credentials = { 18 | tencent: { 19 | SecretId: process.env.TENCENT_SECRET_ID, 20 | SecretKey: process.env.TENCENT_SECRET_KEY 21 | } 22 | } 23 | 24 | const sdk = getServerlessSdk(instanceYaml.org) 25 | 26 | it('should deploy success', async () => { 27 | const instance = await sdk.deploy(instanceYaml, credentials) 28 | 29 | expect(instance).toBeDefined() 30 | expect(instance.instanceName).toEqual(instanceYaml.name) 31 | expect(instance.outputs).toBeDefined() 32 | // get src from template by default 33 | expect(instance.outputs.templateUrl).toBeDefined() 34 | expect(instance.outputs.region).toEqual(instanceYaml.inputs.region) 35 | expect(instance.outputs.apigw).toBeDefined() 36 | expect(instance.outputs.apigw.environment).toEqual(instanceYaml.inputs.apigatewayConf.environment) 37 | 38 | const response = await axios.get(instance.outputs.apigw.url) 39 | expect(response.data.includes('Laravel')).toBeTruthy() 40 | }) 41 | 42 | it('should remove success', async () => { 43 | await sdk.remove(instanceYaml, credentials) 44 | result = await sdk.getInstance( 45 | instanceYaml.org, 46 | instanceYaml.stage, 47 | instanceYaml.app, 48 | instanceYaml.name 49 | ) 50 | 51 | expect(result.instance.instanceStatus).toEqual('inactive') 52 | }) 53 | -------------------------------------------------------------------------------- /__tests__/lib/utils.js: -------------------------------------------------------------------------------- 1 | const { ServerlessSDK } = require('@serverless/platform-client-china') 2 | 3 | /* 4 | * Generate random id 5 | */ 6 | const generateId = () => 7 | Math.random() 8 | .toString(36) 9 | .substring(6) 10 | 11 | /* 12 | * Initializes and returns an instance of the serverless sdk 13 | * @param ${string} orgName - the serverless org name. 14 | */ 15 | const getServerlessSdk = (orgName) => { 16 | const sdk = new ServerlessSDK({ 17 | context: { 18 | orgName 19 | } 20 | }) 21 | return sdk 22 | } 23 | 24 | module.exports = { generateId, getServerlessSdk } 25 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | const Configuration = { 2 | /* 3 | * Resolve and load @commitlint/config-conventional from node_modules. 4 | * Referenced packages must be installed 5 | */ 6 | extends: ['@commitlint/config-conventional'] 7 | } 8 | 9 | module.exports = Configuration 10 | -------------------------------------------------------------------------------- /docs/configure.md: -------------------------------------------------------------------------------- 1 | # 配置文档 2 | 3 | ## 全部配置 4 | 5 | ```yml 6 | # serverless.yml 7 | app: appDemo # (可选) 用于记录组织信息. 默认与name相同,必须为字符串 8 | stage: dev # (可选) 用于区分环境信息,默认值是 dev 9 | 10 | component: laravel # (必选) 组件名称 11 | name: laravelDemo # 必选) 组件实例名称. 12 | 13 | inputs: 14 | region: ap-guangzhou # 云函数所在区域 15 | src: # 部署src下的文件代码,并打包成zip上传到bucket上 16 | src: ./ # 本地需要打包的文件目录 17 | exclude: # 被排除的文件或目录 18 | - .env 19 | - 'node_modules/**' 20 | # src: # 在指定存储桶bucket中已经存在了object代码,直接部署 21 | # bucket: bucket01 # bucket name,当前会默认在bucket name后增加 appid 后缀, 本例中为 bucket01-appid 22 | # object: cos.zip # bucket key 指定存储桶内的文件 23 | functionConf: # 函数配置相关 24 | name: webDemo # 云函数名称 25 | runtime: Php7 # 运行环境 26 | timeout: 10 # 超时时间,单位秒 27 | eip: false # 是否固定出口IP 28 | memorySize: 128 # 内存大小,单位MB 29 | environment: # 环境变量 30 | variables: # 环境变量数组 31 | TEST: vale 32 | vpc: # 私有网络配置 33 | vpcId: 'vpc-xxx' # 私有网络的Id 34 | subnetId: 'subnet-xxx' # 子网ID 35 | layers: 36 | - name: layerName # layer名称 37 | version: 1 # 版本 38 | tags: 39 | tagKey: tagValue 40 | apigatewayConf: # api网关配置 41 | isDisabled: false # 是否禁用自动创建 API 网关功能 42 | isBase64Encoded: false # 是否开启 base64 编码 43 | id: service-np1uloxw # api网关服务ID 44 | name: serverless # api网关服务名称 45 | description: serverless apigw # api网关描述 46 | enableCORS: true # 允许跨域 47 | timeout: 15 # api 超时时间 48 | protocols: 49 | - http 50 | - https 51 | environment: test 52 | customDomains: # 自定义域名绑定 53 | - domain: abc.com # 待绑定的自定义的域名 54 | certificateId: abcdefg # 待绑定自定义域名的证书唯一 ID 55 | # 如要设置自定义路径映射,请设置为 false 56 | isDefaultMapping: false 57 | # 自定义路径映射的路径。使用自定义映射时,可一次仅映射一个 path 到一个环境,也可映射多个 path 到多个环境。并且一旦使用自定义映射,原本的默认映射规则不再生效,只有自定义映射路径生效。 58 | pathMappingSet: 59 | - path: / 60 | environment: release 61 | protocols: # 绑定自定义域名的协议类型,默认与服务的前端协议一致。 62 | - http # 支持http协议 63 | - https # 支持https协议 64 | usagePlan: # 用户使用计划 65 | usagePlanId: 1111 66 | usagePlanName: slscmp 67 | usagePlanDesc: sls create 68 | maxRequestNum: 1000 69 | auth: # 密钥 70 | secretName: secret 71 | secretIds: 72 | - xxx 73 | ``` 74 | 75 | ## inputs 配置参数 76 | 77 | 主要的参数 78 | 79 | | 参数名称 | 必选 | 类型 | 默认值 | 描述 | 80 | | -------------- | :--: | :------------------------ | :-------------: | :--------------- | 81 | | region | 否 | string | `ap-guangzhou` | 项目部署所在区域 | 82 | | src | 否 | [Src](#Src) | `process.cwd()` | 项目代码配置 | 83 | | functionConf | 否 | [Function](#Function) | | 函数配置 | 84 | | apigatewayConf | 否 | [Apigateway](#Apigateway) | | API 网关配置 | 85 | 86 | ## Src 87 | 88 | 项目代码配置 89 | 90 | | 参数名称 | 是否必选 | 类型 | 默认值 | 描述 | 91 | | -------- | :------: | :------: | :----: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 92 | | src | 否 | string | | 代码路径。与 object 不能同时存在。 | 93 | | exclude | 否 | string[] | | 不包含的文件或路径, 遵守 [glob 语法][glob] | 94 | | bucket | 否 | string | | bucket 名称。如果配置了 src,表示部署 src 的代码并压缩成 zip 后上传到 bucket-appid 对应的存储桶中;如果配置了 object,表示获取 bucket-appid 对应存储桶中 object 对应的代码进行部署。 | 95 | | object | 否 | string | | 部署的代码在存储桶中的路径。 | 96 | 97 | ### Function 98 | 99 | 函数配置 100 | 101 | | 参数名称 | 是否必选 | 类型 | 默认值 | 描述 | 102 | | ----------- | :------: | :-------------------------- | :-----: | :------------------------------------------------------------------------------ | 103 | | runtime | 否 | string | `Php7` | 执行环境, 支持: Php7,Php5 | 104 | | timeout | 否 | number | `3` | 函数最长执行时间,单位为秒,可选值范围 1-900 秒,默认为 3 秒 | 105 | | memorySize | 否 | number | `128` | 函数运行时内存大小,默认为 128M,可选范围 64、128MB-3072MB,并且以 128MB 为阶梯 | 106 | | environment | 否 | [Environment](#Environment) | | 函数的环境变量 | 107 | | vpc | 否 | [Vpc](#Vpc) | | 函数的 VPC 配置 | 108 | | layers | 否 | [Layer](#Layer)[] | | 云函数绑定的 layer | 109 | | tags | 否 | object | | 云函数标签,`key-value` 形式配置 | 110 | | eip | 否 | boolean | `false` | 是否固定出口 IP | 111 | 112 | > 此处只是列举,`faas` 参数支持 [scf][scf-config] 组件的所有基础配置( `events` 除外) 113 | 114 | `runtime` 运行环境说明: 115 | 116 | ``` 117 | Nodejs 框架支持:Nodejs6.10, Nodejs8.9, Nodejs10.15, Nodejs12.16 118 | Python 框架支持:Python3.6, Python2.7 119 | PHP 框架支持:Php7,Php5 120 | ``` 121 | 122 | ##### Layer 123 | 124 | 层配置 125 | 126 | | 参数名称 | 是否必选 | 类型 | 默认值 | 描述 | 127 | | -------- | :------: | :----: | :----: | :------- | 128 | | name | 否 | string | | 层名称 | 129 | | version | 否 | string | | 层版本号 | 130 | 131 | ##### Environment 132 | 133 | 环境变量 134 | 135 | | 参数名称 | 类型 | 描述 | 136 | | --------- | ------ | :---------------------------------------- | 137 | | variables | object | 环境变量参数, 包含多对 key-value 的键值对 | 138 | 139 | ##### Vpc 140 | 141 | VPC 配置 142 | 143 | | 参数名称 | 类型 | 描述 | 144 | | -------- | ------ | :---------- | 145 | | vpcId | string | 私有网络 ID | 146 | | subnetId | string | 子网 ID | 147 | 148 | ### Apigateway 149 | 150 | API 网关配置 151 | 152 | | 参数名称 | 是否必选 | 类型 | 默认值 | 描述 | 153 | | --------------- | :------: | :------------------------------ | :----------- | :--------------------------------------------------------------- | 154 | | id | 否 | string | | API 网关服务 ID, 如果存在将使用这个 API 网关服务 | 155 | | name | 否 | string | `serverless` | API 网关服务名称, 默认创建一个新的服务名称 | 156 | | description | 否 | string | `serverless` | API 网关服务描述 | 157 | | protocols | 否 | string[] | `['http']` | 前端请求的类型,如 http,https,http 与 https | 158 | | environment | 否 | string | `release` | 发布环境. 网关环境: test, prepub 与 release | 159 | | usagePlan | 否 | [UsagePlan](#UsagePlan) | | 使用计划配置 | 160 | | auth | 否 | [ApuAuth](#ApiAuth) | | API 密钥配置 | 161 | | customDomain | 否 | [CustomDomain](#CustomDomain)[] | | 自定义 API 域名配置 | 162 | | enableCORS | 否 | boolean | `false` | 开启跨域。默认值为否。 | 163 | | timeout | 否 | number | `15` | Api 超时时间,单位: 秒 | 164 | | isDisabled | 否 | boolean | `false` | 关闭自动创建 API 网关功能。默认值为否,即默认自动创建 API 网关。 | 165 | | isBase64Encoded | 否 | Boolean | `false` | 是否开启 Base64 编码,如果需要文件上传,请配置为 `true` | 166 | 167 | ##### UsagePlan 168 | 169 | 使用计划配置 170 | 171 | 参考: https://cloud.tencent.com/document/product/628/14947 172 | 173 | | 参数名称 | 是否必选 | 类型 | 描述 | 174 | | ------------- | :------: | :----- | :------------------------------------------------------ | 175 | | usagePlanId | 否 | string | 用户自定义使用计划 ID | 176 | | usagePlanName | 否 | string | 用户自定义的使用计划名称 | 177 | | usagePlanDesc | 否 | string | 用户自定义的使用计划描述 | 178 | | maxRequestNum | 否 | number | 请求配额总数,如果为空,将使用-1 作为默认值,表示不开启 | 179 | 180 | ##### ApiAuth 181 | 182 | API 密钥配置 183 | 184 | | 参数名称 | 类型 | 描述 | 185 | | ---------- | :----- | :------- | 186 | | secretName | string | 密钥名称 | 187 | | secretIds | string | 密钥 ID | 188 | 189 | ##### CustomDomain 190 | 191 | 自定义域名配置 192 | 193 | | 参数名称 | 是否必选 | 类型 | 默认值 | 描述 | 194 | | ---------------- | :------: | :-------------------- | :----: | :---------------------------------------------------------------------------------- | 195 | | domain | 是 | string | | 待绑定的自定义的域名。 | 196 | | protocol | 否 | string[] | | 绑定自定义域名的协议类型,默认与服务的前端协议一致。 | 197 | | certificateId | 否 | string | | 待绑定自定义域名的证书 ID,如果设置了 `protocol` 含有 https,则为必选 | 198 | | isDefaultMapping | 否 | string | `true` | 是否使用默认路径映射。为 `false` 时,表示自定义路径映射,此时 pathMappingSet 必填。 | 199 | | pathMappingSet | 否 | [PathMap](#PathMap)[] | `[]` | 自定义路径映射的路径。 | 200 | 201 | > 注意:使用自定义映射时,可一次仅映射一个 path 到一个环境,也可映射多个 path 到多个环境。并且一旦使用自定义映射,原本的默认映射规则不再生效,只有自定义映射路径生效。 202 | 203 | ###### PathMap 204 | 205 | 自定义路径映射 206 | 207 | | 参数名称 | 是否必选 | 类型 | Description | 208 | | ----------- | :------: | :----- | :------------- | 209 | | path | 是 | string | 自定义映射路径 | 210 | | environment | 是 | string | 自定义映射环境 | 211 | 212 | 213 | 214 | [glob]: https://github.com/isaacs/node-glob 215 | [scf-config]: https://github.com/serverless-components/tencent-scf/tree/master/docs/configure.md 216 | -------------------------------------------------------------------------------- /docs/upload.md: -------------------------------------------------------------------------------- 1 | ## 文件上传说明 2 | 3 | 项目中如果涉及到文件上传,需要依赖 API 网关提供的 [Base64 编码能力](https://cloud.tencent.com/document/product/628/51799),使用时只需要 `serverless.yml` 中配置 `isBase64Encoded` 为 `true`,如下: 4 | 5 | ```yaml 6 | app: appDemo 7 | stage: dev 8 | component: laravel 9 | name: laravelDemo 10 | 11 | inputs: 12 | # 省略... 13 | apigatewayConf: 14 | isBase64Encoded: true 15 | # 省略... 16 | # 省略... 17 | ``` 18 | 19 | 当前 API 网关支持上传最大文件大小为 `2M`,如果文件过大,请修改为前端直传对象存储方案。 20 | 21 | ## Base64 示例 22 | 23 | 此 Github 项目的 `example` 目录下 `routes/api.php` 文件中有 `POST /upload` 接口如下: 24 | 25 | ```php 26 | // 上传文件接口 27 | Route::post('/upload', function (Request $request) { 28 | // 表单中字段为 file 29 | if ($request->file) { 30 | // TODO: 这里只是存储在了 /tmp 临时目录下,用户需要根据个人需要存储到持久化存储服务,比如腾讯云的对象存储、文件存储等。 31 | $upload = $request->file->store('upload'); 32 | $uploadFile = storage_path()."/app/".$upload; 33 | } 34 | 35 | return response()->json([ 36 | 'title' => 'serverless', 37 | 'upload' => $uploadFile ?? null, 38 | ]); 39 | }); 40 | ``` 41 | -------------------------------------------------------------------------------- /example/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml,yaml}] 15 | indent_size = 2 16 | -------------------------------------------------------------------------------- /example/.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | 7 | LOG_CHANNEL=stack 8 | 9 | DB_CONNECTION=mysql 10 | DB_HOST=127.0.0.1 11 | DB_PORT=3306 12 | DB_DATABASE=laravel 13 | DB_USERNAME=root 14 | DB_PASSWORD= 15 | 16 | BROADCAST_DRIVER=log 17 | CACHE_DRIVER=file 18 | QUEUE_CONNECTION=sync 19 | SESSION_DRIVER=file 20 | SESSION_LIFETIME=120 21 | 22 | REDIS_HOST=127.0.0.1 23 | REDIS_PASSWORD=null 24 | REDIS_PORT=6379 25 | 26 | MAIL_MAILER=smtp 27 | MAIL_HOST=smtp.mailtrap.io 28 | MAIL_PORT=2525 29 | MAIL_USERNAME=null 30 | MAIL_PASSWORD=null 31 | MAIL_ENCRYPTION=null 32 | MAIL_FROM_ADDRESS=null 33 | MAIL_FROM_NAME="${APP_NAME}" 34 | 35 | AWS_ACCESS_KEY_ID= 36 | AWS_SECRET_ACCESS_KEY= 37 | AWS_DEFAULT_REGION=us-east-1 38 | AWS_BUCKET= 39 | 40 | PUSHER_APP_ID= 41 | PUSHER_APP_KEY= 42 | PUSHER_APP_SECRET= 43 | PUSHER_APP_CLUSTER=mt1 44 | 45 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 46 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 47 | 48 | # tencent crendential 49 | TENCENT_SECRET_ID=xxx 50 | TENCENT_SECRET_KEY=xxx 51 | -------------------------------------------------------------------------------- /example/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.css linguist-vendored 3 | *.scss linguist-vendored 4 | *.js linguist-vendored 5 | CHANGELOG.md export-ignore 6 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /public/hot 3 | /public/storage 4 | /storage/*.key 5 | /vendor 6 | .env 7 | .env.backup 8 | .phpunit.result.cache 9 | Homestead.json 10 | Homestead.yaml 11 | npm-debug.log 12 | yarn-error.log 13 | 14 | /storage/ 15 | -------------------------------------------------------------------------------- /example/.styleci.yml: -------------------------------------------------------------------------------- 1 | php: 2 | preset: laravel 3 | disabled: 4 | - unused_use 5 | finder: 6 | not-name: 7 | - index.php 8 | - server.php 9 | js: 10 | finder: 11 | not-name: 12 | - webpack.mix.js 13 | css: true 14 | -------------------------------------------------------------------------------- /example/app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('inspire')->hourly(); 28 | } 29 | 30 | /** 31 | * Register the commands for the application. 32 | * 33 | * @return void 34 | */ 35 | protected function commands() 36 | { 37 | $this->load(__DIR__.'/Commands'); 38 | 39 | require base_path('routes/console.php'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /example/app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | [ 33 | \App\Http\Middleware\EncryptCookies::class, 34 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 35 | \Illuminate\Session\Middleware\StartSession::class, 36 | // \Illuminate\Session\Middleware\AuthenticateSession::class, 37 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 38 | \App\Http\Middleware\VerifyCsrfToken::class, 39 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 40 | ], 41 | 42 | 'api' => [ 43 | 'throttle:60,1', 44 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 45 | ], 46 | ]; 47 | 48 | /** 49 | * The application's route middleware. 50 | * 51 | * These middleware may be assigned to groups or used individually. 52 | * 53 | * @var array 54 | */ 55 | protected $routeMiddleware = [ 56 | 'auth' => \App\Http\Middleware\Authenticate::class, 57 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 58 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 59 | 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 60 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 61 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 62 | 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, 63 | 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 64 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 65 | 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 66 | ]; 67 | } 68 | -------------------------------------------------------------------------------- /example/app/Http/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | expectsJson()) { 18 | return route('login'); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/app/Http/Middleware/CheckForMaintenanceMode.php: -------------------------------------------------------------------------------- 1 | check()) { 22 | return redirect(RouteServiceProvider::HOME); 23 | } 24 | 25 | return $next($request); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /example/app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | allSubdomainsOfApplicationUrl(), 18 | ]; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /example/app/Http/Middleware/TrustProxies.php: -------------------------------------------------------------------------------- 1 | 'App\Policies\ModelPolicy', 17 | ]; 18 | 19 | /** 20 | * Register any authentication / authorization services. 21 | * 22 | * @return void 23 | */ 24 | public function boot() 25 | { 26 | $this->registerPolicies(); 27 | 28 | // 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /example/app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | [ 19 | SendEmailVerificationNotification::class, 20 | ], 21 | ]; 22 | 23 | /** 24 | * Register any events for your application. 25 | * 26 | * @return void 27 | */ 28 | public function boot() 29 | { 30 | parent::boot(); 31 | 32 | // 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /example/app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | mapApiRoutes(); 46 | 47 | $this->mapWebRoutes(); 48 | 49 | // 50 | } 51 | 52 | /** 53 | * Define the "web" routes for the application. 54 | * 55 | * These routes all receive session state, CSRF protection, etc. 56 | * 57 | * @return void 58 | */ 59 | protected function mapWebRoutes() 60 | { 61 | Route::middleware('web') 62 | ->namespace($this->namespace) 63 | ->group(base_path('routes/web.php')); 64 | } 65 | 66 | /** 67 | * Define the "api" routes for the application. 68 | * 69 | * These routes are typically stateless. 70 | * 71 | * @return void 72 | */ 73 | protected function mapApiRoutes() 74 | { 75 | Route::prefix('api') 76 | ->middleware('api') 77 | ->namespace($this->namespace) 78 | ->group(base_path('routes/api.php')); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /example/app/User.php: -------------------------------------------------------------------------------- 1 | 'datetime', 38 | ]; 39 | } 40 | -------------------------------------------------------------------------------- /example/artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | make(Illuminate\Contracts\Console\Kernel::class); 34 | 35 | $status = $kernel->handle( 36 | $input = new Symfony\Component\Console\Input\ArgvInput, 37 | new Symfony\Component\Console\Output\ConsoleOutput 38 | ); 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Shutdown The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once Artisan has finished running, we will fire off the shutdown events 46 | | so that any final work may be done by the application before we shut 47 | | down the process. This is the last thing to happen to the request. 48 | | 49 | */ 50 | 51 | $kernel->terminate($input, $status); 52 | 53 | exit($status); 54 | -------------------------------------------------------------------------------- /example/bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /example/bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /example/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel/laravel", 3 | "type": "project", 4 | "description": "The Laravel Framework.", 5 | "keywords": [ 6 | "framework", 7 | "laravel" 8 | ], 9 | "license": "MIT", 10 | "require": { 11 | "php": "^7.2.5", 12 | "fideloper/proxy": "^4.2", 13 | "fruitcake/laravel-cors": "^1.0", 14 | "guzzlehttp/guzzle": "^6.3", 15 | "laravel/framework": "^7.0", 16 | "laravel/tinker": "^2.0" 17 | }, 18 | "require-dev": { 19 | "facade/ignition": "^2.0", 20 | "fzaninotto/faker": "^1.9.1", 21 | "mockery/mockery": "^1.3.1", 22 | "nunomaduro/collision": "^4.1", 23 | "phpunit/phpunit": "^8.5" 24 | }, 25 | "config": { 26 | "optimize-autoloader": true, 27 | "preferred-install": "dist", 28 | "sort-packages": true 29 | }, 30 | "extra": { 31 | "laravel": { 32 | "dont-discover": [] 33 | } 34 | }, 35 | "autoload": { 36 | "psr-4": { 37 | "App\\": "app/" 38 | }, 39 | "classmap": [ 40 | "database/seeds", 41 | "database/factories" 42 | ] 43 | }, 44 | "autoload-dev": { 45 | "psr-4": { 46 | "Tests\\": "tests/" 47 | } 48 | }, 49 | "minimum-stability": "dev", 50 | "prefer-stable": true, 51 | "scripts": { 52 | "post-autoload-dump": [ 53 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 54 | "@php artisan package:discover --ansi" 55 | ], 56 | "post-root-package-install": [ 57 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 58 | ], 59 | "post-create-project-cmd": [ 60 | "@php artisan key:generate --ansi" 61 | ] 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /example/config/app.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Application Environment 21 | |-------------------------------------------------------------------------- 22 | | 23 | | This value determines the "environment" your application is currently 24 | | running in. This may determine how you prefer to configure various 25 | | services the application utilizes. Set this in your ".env" file. 26 | | 27 | */ 28 | 29 | 'env' => env('APP_ENV', 'production'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Application Debug Mode 34 | |-------------------------------------------------------------------------- 35 | | 36 | | When your application is in debug mode, detailed error messages with 37 | | stack traces will be shown on every error that occurs within your 38 | | application. If disabled, a simple generic error page is shown. 39 | | 40 | */ 41 | 42 | 'debug' => (bool) env('APP_DEBUG', false), 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Application URL 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This URL is used by the console to properly generate URLs when using 50 | | the Artisan command line tool. You should set this to the root of 51 | | your application so that it is used when running Artisan tasks. 52 | | 53 | */ 54 | 55 | 'url' => env('APP_URL', 'http://localhost'), 56 | 57 | 'asset_url' => env('ASSET_URL', null), 58 | 59 | /* 60 | |-------------------------------------------------------------------------- 61 | | Application Timezone 62 | |-------------------------------------------------------------------------- 63 | | 64 | | Here you may specify the default timezone for your application, which 65 | | will be used by the PHP date and date-time functions. We have gone 66 | | ahead and set this to a sensible default for you out of the box. 67 | | 68 | */ 69 | 70 | 'timezone' => 'UTC', 71 | 72 | /* 73 | |-------------------------------------------------------------------------- 74 | | Application Locale Configuration 75 | |-------------------------------------------------------------------------- 76 | | 77 | | The application locale determines the default locale that will be used 78 | | by the translation service provider. You are free to set this value 79 | | to any of the locales which will be supported by the application. 80 | | 81 | */ 82 | 83 | 'locale' => 'en', 84 | 85 | /* 86 | |-------------------------------------------------------------------------- 87 | | Application Fallback Locale 88 | |-------------------------------------------------------------------------- 89 | | 90 | | The fallback locale determines the locale to use when the current one 91 | | is not available. You may change the value to correspond to any of 92 | | the language folders that are provided through your application. 93 | | 94 | */ 95 | 96 | 'fallback_locale' => 'en', 97 | 98 | /* 99 | |-------------------------------------------------------------------------- 100 | | Faker Locale 101 | |-------------------------------------------------------------------------- 102 | | 103 | | This locale will be used by the Faker PHP library when generating fake 104 | | data for your database seeds. For example, this will be used to get 105 | | localized telephone numbers, street address information and more. 106 | | 107 | */ 108 | 109 | 'faker_locale' => 'en_US', 110 | 111 | /* 112 | |-------------------------------------------------------------------------- 113 | | Encryption Key 114 | |-------------------------------------------------------------------------- 115 | | 116 | | This key is used by the Illuminate encrypter service and should be set 117 | | to a random, 32 character string, otherwise these encrypted strings 118 | | will not be safe. Please do this before deploying an application! 119 | | 120 | */ 121 | 122 | 'key' => env('APP_KEY'), 123 | 124 | 'cipher' => 'AES-256-CBC', 125 | 126 | /* 127 | |-------------------------------------------------------------------------- 128 | | Autoloaded Service Providers 129 | |-------------------------------------------------------------------------- 130 | | 131 | | The service providers listed here will be automatically loaded on the 132 | | request to your application. Feel free to add your own services to 133 | | this array to grant expanded functionality to your applications. 134 | | 135 | */ 136 | 137 | 'providers' => [ 138 | 139 | /* 140 | * Laravel Framework Service Providers... 141 | */ 142 | Illuminate\Auth\AuthServiceProvider::class, 143 | Illuminate\Broadcasting\BroadcastServiceProvider::class, 144 | Illuminate\Bus\BusServiceProvider::class, 145 | Illuminate\Cache\CacheServiceProvider::class, 146 | Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, 147 | Illuminate\Cookie\CookieServiceProvider::class, 148 | Illuminate\Database\DatabaseServiceProvider::class, 149 | Illuminate\Encryption\EncryptionServiceProvider::class, 150 | Illuminate\Filesystem\FilesystemServiceProvider::class, 151 | Illuminate\Foundation\Providers\FoundationServiceProvider::class, 152 | Illuminate\Hashing\HashServiceProvider::class, 153 | Illuminate\Mail\MailServiceProvider::class, 154 | Illuminate\Notifications\NotificationServiceProvider::class, 155 | Illuminate\Pagination\PaginationServiceProvider::class, 156 | Illuminate\Pipeline\PipelineServiceProvider::class, 157 | Illuminate\Queue\QueueServiceProvider::class, 158 | Illuminate\Redis\RedisServiceProvider::class, 159 | Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, 160 | Illuminate\Session\SessionServiceProvider::class, 161 | Illuminate\Translation\TranslationServiceProvider::class, 162 | Illuminate\Validation\ValidationServiceProvider::class, 163 | Illuminate\View\ViewServiceProvider::class, 164 | 165 | /* 166 | * Package Service Providers... 167 | */ 168 | 169 | /* 170 | * Application Service Providers... 171 | */ 172 | App\Providers\AppServiceProvider::class, 173 | App\Providers\AuthServiceProvider::class, 174 | // App\Providers\BroadcastServiceProvider::class, 175 | App\Providers\EventServiceProvider::class, 176 | App\Providers\RouteServiceProvider::class, 177 | 178 | ], 179 | 180 | /* 181 | |-------------------------------------------------------------------------- 182 | | Class Aliases 183 | |-------------------------------------------------------------------------- 184 | | 185 | | This array of class aliases will be registered when this application 186 | | is started. However, feel free to register as many as you wish as 187 | | the aliases are "lazy" loaded so they don't hinder performance. 188 | | 189 | */ 190 | 191 | 'aliases' => [ 192 | 193 | 'App' => Illuminate\Support\Facades\App::class, 194 | 'Arr' => Illuminate\Support\Arr::class, 195 | 'Artisan' => Illuminate\Support\Facades\Artisan::class, 196 | 'Auth' => Illuminate\Support\Facades\Auth::class, 197 | 'Blade' => Illuminate\Support\Facades\Blade::class, 198 | 'Broadcast' => Illuminate\Support\Facades\Broadcast::class, 199 | 'Bus' => Illuminate\Support\Facades\Bus::class, 200 | 'Cache' => Illuminate\Support\Facades\Cache::class, 201 | 'Config' => Illuminate\Support\Facades\Config::class, 202 | 'Cookie' => Illuminate\Support\Facades\Cookie::class, 203 | 'Crypt' => Illuminate\Support\Facades\Crypt::class, 204 | 'DB' => Illuminate\Support\Facades\DB::class, 205 | 'Eloquent' => Illuminate\Database\Eloquent\Model::class, 206 | 'Event' => Illuminate\Support\Facades\Event::class, 207 | 'File' => Illuminate\Support\Facades\File::class, 208 | 'Gate' => Illuminate\Support\Facades\Gate::class, 209 | 'Hash' => Illuminate\Support\Facades\Hash::class, 210 | 'Http' => Illuminate\Support\Facades\Http::class, 211 | 'Lang' => Illuminate\Support\Facades\Lang::class, 212 | 'Log' => Illuminate\Support\Facades\Log::class, 213 | 'Mail' => Illuminate\Support\Facades\Mail::class, 214 | 'Notification' => Illuminate\Support\Facades\Notification::class, 215 | 'Password' => Illuminate\Support\Facades\Password::class, 216 | 'Queue' => Illuminate\Support\Facades\Queue::class, 217 | 'Redirect' => Illuminate\Support\Facades\Redirect::class, 218 | 'Redis' => Illuminate\Support\Facades\Redis::class, 219 | 'Request' => Illuminate\Support\Facades\Request::class, 220 | 'Response' => Illuminate\Support\Facades\Response::class, 221 | 'Route' => Illuminate\Support\Facades\Route::class, 222 | 'Schema' => Illuminate\Support\Facades\Schema::class, 223 | 'Session' => Illuminate\Support\Facades\Session::class, 224 | 'Storage' => Illuminate\Support\Facades\Storage::class, 225 | 'Str' => Illuminate\Support\Str::class, 226 | 'URL' => Illuminate\Support\Facades\URL::class, 227 | 'Validator' => Illuminate\Support\Facades\Validator::class, 228 | 'View' => Illuminate\Support\Facades\View::class, 229 | 230 | ], 231 | 232 | ]; 233 | -------------------------------------------------------------------------------- /example/config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => 'web', 18 | 'passwords' => 'users', 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | here which uses session storage and the Eloquent user provider. 29 | | 30 | | All authentication drivers have a user provider. This defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | mechanisms used by this application to persist your user's data. 33 | | 34 | | Supported: "session", "token" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | 44 | 'api' => [ 45 | 'driver' => 'token', 46 | 'provider' => 'users', 47 | 'hash' => false, 48 | ], 49 | ], 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | User Providers 54 | |-------------------------------------------------------------------------- 55 | | 56 | | All authentication drivers have a user provider. This defines how the 57 | | users are actually retrieved out of your database or other storage 58 | | mechanisms used by this application to persist your user's data. 59 | | 60 | | If you have multiple user tables or models you may configure multiple 61 | | sources which represent each model / table. These sources may then 62 | | be assigned to any extra authentication guards you have defined. 63 | | 64 | | Supported: "database", "eloquent" 65 | | 66 | */ 67 | 68 | 'providers' => [ 69 | 'users' => [ 70 | 'driver' => 'eloquent', 71 | 'model' => App\User::class, 72 | ], 73 | 74 | // 'users' => [ 75 | // 'driver' => 'database', 76 | // 'table' => 'users', 77 | // ], 78 | ], 79 | 80 | /* 81 | |-------------------------------------------------------------------------- 82 | | Resetting Passwords 83 | |-------------------------------------------------------------------------- 84 | | 85 | | You may specify multiple password reset configurations if you have more 86 | | than one user table or model in the application and you want to have 87 | | separate password reset settings based on the specific user types. 88 | | 89 | | The expire time is the number of minutes that the reset token should be 90 | | considered valid. This security feature keeps tokens short-lived so 91 | | they have less time to be guessed. You may change this as needed. 92 | | 93 | */ 94 | 95 | 'passwords' => [ 96 | 'users' => [ 97 | 'provider' => 'users', 98 | 'table' => 'password_resets', 99 | 'expire' => 60, 100 | 'throttle' => 60, 101 | ], 102 | ], 103 | 104 | /* 105 | |-------------------------------------------------------------------------- 106 | | Password Confirmation Timeout 107 | |-------------------------------------------------------------------------- 108 | | 109 | | Here you may define the amount of seconds before a password confirmation 110 | | times out and the user is prompted to re-enter their password via the 111 | | confirmation screen. By default, the timeout lasts for three hours. 112 | | 113 | */ 114 | 115 | 'password_timeout' => 10800, 116 | 117 | ]; 118 | -------------------------------------------------------------------------------- /example/config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'null'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Broadcast Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the broadcast connections that will be used 26 | | to broadcast events to other systems or over websockets. Samples of 27 | | each available type of connection are provided inside this array. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'pusher' => [ 34 | 'driver' => 'pusher', 35 | 'key' => env('PUSHER_APP_KEY'), 36 | 'secret' => env('PUSHER_APP_SECRET'), 37 | 'app_id' => env('PUSHER_APP_ID'), 38 | 'options' => [ 39 | 'cluster' => env('PUSHER_APP_CLUSTER'), 40 | 'useTLS' => true, 41 | ], 42 | ], 43 | 44 | 'redis' => [ 45 | 'driver' => 'redis', 46 | 'connection' => 'default', 47 | ], 48 | 49 | 'log' => [ 50 | 'driver' => 'log', 51 | ], 52 | 53 | 'null' => [ 54 | 'driver' => 'null', 55 | ], 56 | 57 | ], 58 | 59 | ]; 60 | -------------------------------------------------------------------------------- /example/config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Cache Stores 26 | |-------------------------------------------------------------------------- 27 | | 28 | | Here you may define all of the cache "stores" for your application as 29 | | well as their drivers. You may even define multiple stores for the 30 | | same cache driver to group types of items stored in your caches. 31 | | 32 | */ 33 | 34 | 'stores' => [ 35 | 36 | 'apc' => [ 37 | 'driver' => 'apc', 38 | ], 39 | 40 | 'array' => [ 41 | 'driver' => 'array', 42 | 'serialize' => false, 43 | ], 44 | 45 | 'database' => [ 46 | 'driver' => 'database', 47 | 'table' => 'cache', 48 | 'connection' => null, 49 | ], 50 | 51 | 'file' => [ 52 | 'driver' => 'file', 53 | 'path' => storage_path('framework/cache/data'), 54 | ], 55 | 56 | 'memcached' => [ 57 | 'driver' => 'memcached', 58 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 59 | 'sasl' => [ 60 | env('MEMCACHED_USERNAME'), 61 | env('MEMCACHED_PASSWORD'), 62 | ], 63 | 'options' => [ 64 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 65 | ], 66 | 'servers' => [ 67 | [ 68 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 69 | 'port' => env('MEMCACHED_PORT', 11211), 70 | 'weight' => 100, 71 | ], 72 | ], 73 | ], 74 | 75 | 'redis' => [ 76 | 'driver' => 'redis', 77 | 'connection' => 'cache', 78 | ], 79 | 80 | 'dynamodb' => [ 81 | 'driver' => 'dynamodb', 82 | 'key' => env('AWS_ACCESS_KEY_ID'), 83 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 84 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 85 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 86 | 'endpoint' => env('DYNAMODB_ENDPOINT'), 87 | ], 88 | 89 | ], 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Cache Key Prefix 94 | |-------------------------------------------------------------------------- 95 | | 96 | | When utilizing a RAM based store such as APC or Memcached, there might 97 | | be other applications utilizing the same cache. So, we'll specify a 98 | | value to get prefixed to all our keys so we can avoid collisions. 99 | | 100 | */ 101 | 102 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'), 103 | 104 | ]; 105 | -------------------------------------------------------------------------------- /example/config/cors.php: -------------------------------------------------------------------------------- 1 | ['api/*'], 19 | 20 | 'allowed_methods' => ['*'], 21 | 22 | 'allowed_origins' => ['*'], 23 | 24 | 'allowed_origins_patterns' => [], 25 | 26 | 'allowed_headers' => ['*'], 27 | 28 | 'exposed_headers' => [], 29 | 30 | 'max_age' => 0, 31 | 32 | 'supports_credentials' => false, 33 | 34 | ]; 35 | -------------------------------------------------------------------------------- /example/config/database.php: -------------------------------------------------------------------------------- 1 | env('DB_CONNECTION', 'mysql'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Database Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here are each of the database connections setup for your application. 26 | | Of course, examples of configuring each database platform that is 27 | | supported by Laravel is shown below to make development simple. 28 | | 29 | | 30 | | All database work in Laravel is done through the PHP PDO facilities 31 | | so make sure you have the driver for your particular database of 32 | | choice installed on your machine before you begin development. 33 | | 34 | */ 35 | 36 | 'connections' => [ 37 | 38 | 'sqlite' => [ 39 | 'driver' => 'sqlite', 40 | 'url' => env('DATABASE_URL'), 41 | 'database' => env('DB_DATABASE', database_path('database.sqlite')), 42 | 'prefix' => '', 43 | 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), 44 | ], 45 | 46 | 'mysql' => [ 47 | 'driver' => 'mysql', 48 | 'url' => env('DATABASE_URL'), 49 | 'host' => env('DB_HOST', '127.0.0.1'), 50 | 'port' => env('DB_PORT', '3306'), 51 | 'database' => env('DB_DATABASE', 'forge'), 52 | 'username' => env('DB_USERNAME', 'forge'), 53 | 'password' => env('DB_PASSWORD', ''), 54 | 'unix_socket' => env('DB_SOCKET', ''), 55 | 'charset' => 'utf8mb4', 56 | 'collation' => 'utf8mb4_unicode_ci', 57 | 'prefix' => '', 58 | 'prefix_indexes' => true, 59 | 'strict' => true, 60 | 'engine' => null, 61 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 62 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 63 | ]) : [], 64 | ], 65 | 66 | 'pgsql' => [ 67 | 'driver' => 'pgsql', 68 | 'url' => env('DATABASE_URL'), 69 | 'host' => env('DB_HOST', '127.0.0.1'), 70 | 'port' => env('DB_PORT', '5432'), 71 | 'database' => env('DB_DATABASE', 'forge'), 72 | 'username' => env('DB_USERNAME', 'forge'), 73 | 'password' => env('DB_PASSWORD', ''), 74 | 'charset' => 'utf8', 75 | 'prefix' => '', 76 | 'prefix_indexes' => true, 77 | 'schema' => 'public', 78 | 'sslmode' => 'prefer', 79 | ], 80 | 81 | 'sqlsrv' => [ 82 | 'driver' => 'sqlsrv', 83 | 'url' => env('DATABASE_URL'), 84 | 'host' => env('DB_HOST', 'localhost'), 85 | 'port' => env('DB_PORT', '1433'), 86 | 'database' => env('DB_DATABASE', 'forge'), 87 | 'username' => env('DB_USERNAME', 'forge'), 88 | 'password' => env('DB_PASSWORD', ''), 89 | 'charset' => 'utf8', 90 | 'prefix' => '', 91 | 'prefix_indexes' => true, 92 | ], 93 | 94 | ], 95 | 96 | /* 97 | |-------------------------------------------------------------------------- 98 | | Migration Repository Table 99 | |-------------------------------------------------------------------------- 100 | | 101 | | This table keeps track of all the migrations that have already run for 102 | | your application. Using this information, we can determine which of 103 | | the migrations on disk haven't actually been run in the database. 104 | | 105 | */ 106 | 107 | 'migrations' => 'migrations', 108 | 109 | /* 110 | |-------------------------------------------------------------------------- 111 | | Redis Databases 112 | |-------------------------------------------------------------------------- 113 | | 114 | | Redis is an open source, fast, and advanced key-value store that also 115 | | provides a richer body of commands than a typical key-value system 116 | | such as APC or Memcached. Laravel makes it easy to dig right in. 117 | | 118 | */ 119 | 120 | 'redis' => [ 121 | 122 | 'client' => env('REDIS_CLIENT', 'phpredis'), 123 | 124 | 'options' => [ 125 | 'cluster' => env('REDIS_CLUSTER', 'redis'), 126 | 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), 127 | ], 128 | 129 | 'default' => [ 130 | 'url' => env('REDIS_URL'), 131 | 'host' => env('REDIS_HOST', '127.0.0.1'), 132 | 'password' => env('REDIS_PASSWORD', null), 133 | 'port' => env('REDIS_PORT', '6379'), 134 | 'database' => env('REDIS_DB', '0'), 135 | ], 136 | 137 | 'cache' => [ 138 | 'url' => env('REDIS_URL'), 139 | 'host' => env('REDIS_HOST', '127.0.0.1'), 140 | 'password' => env('REDIS_PASSWORD', null), 141 | 'port' => env('REDIS_PORT', '6379'), 142 | 'database' => env('REDIS_CACHE_DB', '1'), 143 | ], 144 | 145 | ], 146 | 147 | ]; 148 | -------------------------------------------------------------------------------- /example/config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DRIVER', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Default Cloud Filesystem Disk 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Many applications store files both locally and in the cloud. For this 24 | | reason, you may specify a default "cloud" driver here. This driver 25 | | will be bound as the Cloud disk implementation in the container. 26 | | 27 | */ 28 | 29 | 'cloud' => env('FILESYSTEM_CLOUD', 's3'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Filesystem Disks 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here you may configure as many filesystem "disks" as you wish, and you 37 | | may even configure multiple disks of the same driver. Defaults have 38 | | been setup for each driver as an example of the required options. 39 | | 40 | | Supported Drivers: "local", "ftp", "sftp", "s3" 41 | | 42 | */ 43 | 44 | 'disks' => [ 45 | 46 | 'local' => [ 47 | 'driver' => 'local', 48 | 'root' => storage_path('app'), 49 | ], 50 | 51 | 'public' => [ 52 | 'driver' => 'local', 53 | 'root' => storage_path('app/public'), 54 | 'url' => env('APP_URL').'/storage', 55 | 'visibility' => 'public', 56 | ], 57 | 58 | 's3' => [ 59 | 'driver' => 's3', 60 | 'key' => env('AWS_ACCESS_KEY_ID'), 61 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 62 | 'region' => env('AWS_DEFAULT_REGION'), 63 | 'bucket' => env('AWS_BUCKET'), 64 | 'url' => env('AWS_URL'), 65 | 'endpoint' => env('AWS_ENDPOINT'), 66 | ], 67 | 68 | ], 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Symbolic Links 73 | |-------------------------------------------------------------------------- 74 | | 75 | | Here you may configure the symbolic links that will be created when the 76 | | `storage:link` Artisan command is executed. The array keys should be 77 | | the locations of the links and the values should be their targets. 78 | | 79 | */ 80 | 81 | 'links' => [ 82 | public_path('storage') => storage_path('app/public'), 83 | ], 84 | 85 | ]; 86 | -------------------------------------------------------------------------------- /example/config/hashing.php: -------------------------------------------------------------------------------- 1 | 'bcrypt', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Bcrypt Options 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may specify the configuration options that should be used when 26 | | passwords are hashed using the Bcrypt algorithm. This will allow you 27 | | to control the amount of time it takes to hash the given password. 28 | | 29 | */ 30 | 31 | 'bcrypt' => [ 32 | 'rounds' => env('BCRYPT_ROUNDS', 10), 33 | ], 34 | 35 | /* 36 | |-------------------------------------------------------------------------- 37 | | Argon Options 38 | |-------------------------------------------------------------------------- 39 | | 40 | | Here you may specify the configuration options that should be used when 41 | | passwords are hashed using the Argon algorithm. These will allow you 42 | | to control the amount of time it takes to hash the given password. 43 | | 44 | */ 45 | 46 | 'argon' => [ 47 | 'memory' => 1024, 48 | 'threads' => 2, 49 | 'time' => 2, 50 | ], 51 | 52 | ]; 53 | -------------------------------------------------------------------------------- /example/config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 21 | 22 | /* 23 | |-------------------------------------------------------------------------- 24 | | Log Channels 25 | |-------------------------------------------------------------------------- 26 | | 27 | | Here you may configure the log channels for your application. Out of 28 | | the box, Laravel uses the Monolog PHP logging library. This gives 29 | | you a variety of powerful log handlers / formatters to utilize. 30 | | 31 | | Available Drivers: "single", "daily", "slack", "syslog", 32 | | "errorlog", "monolog", 33 | | "custom", "stack" 34 | | 35 | */ 36 | 37 | 'channels' => [ 38 | 'stack' => [ 39 | 'driver' => 'stack', 40 | 'channels' => ['single'], 41 | 'ignore_exceptions' => false, 42 | ], 43 | 44 | 'single' => [ 45 | 'driver' => 'single', 46 | 'path' => storage_path('logs/laravel.log'), 47 | 'level' => 'debug', 48 | ], 49 | 50 | 'daily' => [ 51 | 'driver' => 'daily', 52 | 'path' => storage_path('logs/laravel.log'), 53 | 'level' => 'debug', 54 | 'days' => 14, 55 | ], 56 | 57 | 'slack' => [ 58 | 'driver' => 'slack', 59 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 60 | 'username' => 'Laravel Log', 61 | 'emoji' => ':boom:', 62 | 'level' => 'critical', 63 | ], 64 | 65 | 'papertrail' => [ 66 | 'driver' => 'monolog', 67 | 'level' => 'debug', 68 | 'handler' => SyslogUdpHandler::class, 69 | 'handler_with' => [ 70 | 'host' => env('PAPERTRAIL_URL'), 71 | 'port' => env('PAPERTRAIL_PORT'), 72 | ], 73 | ], 74 | 75 | 'stderr' => [ 76 | 'driver' => 'monolog', 77 | 'handler' => StreamHandler::class, 78 | 'formatter' => env('LOG_STDERR_FORMATTER'), 79 | 'with' => [ 80 | 'stream' => 'php://stderr', 81 | ], 82 | ], 83 | 84 | 'syslog' => [ 85 | 'driver' => 'syslog', 86 | 'level' => 'debug', 87 | ], 88 | 89 | 'errorlog' => [ 90 | 'driver' => 'errorlog', 91 | 'level' => 'debug', 92 | ], 93 | 94 | 'null' => [ 95 | 'driver' => 'monolog', 96 | 'handler' => NullHandler::class, 97 | ], 98 | 99 | 'emergency' => [ 100 | 'path' => storage_path('logs/laravel.log'), 101 | ], 102 | ], 103 | 104 | ]; 105 | -------------------------------------------------------------------------------- /example/config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_MAILER', 'smtp'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Mailer Configurations 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure all of the mailers used by your application plus 24 | | their respective settings. Several examples have been configured for 25 | | you and you are free to add your own as your application requires. 26 | | 27 | | Laravel supports a variety of mail "transport" drivers to be used while 28 | | sending an e-mail. You will specify which one you are using for your 29 | | mailers below. You are free to add additional mailers as required. 30 | | 31 | | Supported: "smtp", "sendmail", "mailgun", "ses", 32 | | "postmark", "log", "array" 33 | | 34 | */ 35 | 36 | 'mailers' => [ 37 | 'smtp' => [ 38 | 'transport' => 'smtp', 39 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 40 | 'port' => env('MAIL_PORT', 587), 41 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 42 | 'username' => env('MAIL_USERNAME'), 43 | 'password' => env('MAIL_PASSWORD'), 44 | 'timeout' => null, 45 | 'auth_mode' => null, 46 | ], 47 | 48 | 'ses' => [ 49 | 'transport' => 'ses', 50 | ], 51 | 52 | 'mailgun' => [ 53 | 'transport' => 'mailgun', 54 | ], 55 | 56 | 'postmark' => [ 57 | 'transport' => 'postmark', 58 | ], 59 | 60 | 'sendmail' => [ 61 | 'transport' => 'sendmail', 62 | 'path' => '/usr/sbin/sendmail -bs', 63 | ], 64 | 65 | 'log' => [ 66 | 'transport' => 'log', 67 | 'channel' => env('MAIL_LOG_CHANNEL'), 68 | ], 69 | 70 | 'array' => [ 71 | 'transport' => 'array', 72 | ], 73 | ], 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Global "From" Address 78 | |-------------------------------------------------------------------------- 79 | | 80 | | You may wish for all e-mails sent by your application to be sent from 81 | | the same address. Here, you may specify a name and address that is 82 | | used globally for all e-mails that are sent by your application. 83 | | 84 | */ 85 | 86 | 'from' => [ 87 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 88 | 'name' => env('MAIL_FROM_NAME', 'Example'), 89 | ], 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Markdown Mail Settings 94 | |-------------------------------------------------------------------------- 95 | | 96 | | If you are using Markdown based email rendering, you may configure your 97 | | theme and component paths here, allowing you to customize the design 98 | | of the emails. Or, you may simply stick with the Laravel defaults! 99 | | 100 | */ 101 | 102 | 'markdown' => [ 103 | 'theme' => 'default', 104 | 105 | 'paths' => [ 106 | resource_path('views/vendor/mail'), 107 | ], 108 | ], 109 | 110 | ]; 111 | -------------------------------------------------------------------------------- /example/config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_CONNECTION', 'sync'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Queue Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the connection information for each server that 24 | | is used by your application. A default configuration has been added 25 | | for each back-end shipped with Laravel. You are free to add more. 26 | | 27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'table' => 'jobs', 40 | 'queue' => 'default', 41 | 'retry_after' => 90, 42 | ], 43 | 44 | 'beanstalkd' => [ 45 | 'driver' => 'beanstalkd', 46 | 'host' => 'localhost', 47 | 'queue' => 'default', 48 | 'retry_after' => 90, 49 | 'block_for' => 0, 50 | ], 51 | 52 | 'sqs' => [ 53 | 'driver' => 'sqs', 54 | 'key' => env('AWS_ACCESS_KEY_ID'), 55 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 56 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 57 | 'queue' => env('SQS_QUEUE', 'your-queue-name'), 58 | 'suffix' => env('SQS_SUFFIX'), 59 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 60 | ], 61 | 62 | 'redis' => [ 63 | 'driver' => 'redis', 64 | 'connection' => 'default', 65 | 'queue' => env('REDIS_QUEUE', 'default'), 66 | 'retry_after' => 90, 67 | 'block_for' => null, 68 | ], 69 | 70 | ], 71 | 72 | /* 73 | |-------------------------------------------------------------------------- 74 | | Failed Queue Jobs 75 | |-------------------------------------------------------------------------- 76 | | 77 | | These options configure the behavior of failed queue job logging so you 78 | | can control which database and table are used to store the jobs that 79 | | have failed. You may change them to any database / table you wish. 80 | | 81 | */ 82 | 83 | 'failed' => [ 84 | 'driver' => env('QUEUE_FAILED_DRIVER', 'database'), 85 | 'database' => env('DB_CONNECTION', 'mysql'), 86 | 'table' => 'failed_jobs', 87 | ], 88 | 89 | ]; 90 | -------------------------------------------------------------------------------- /example/config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 21 | ], 22 | 23 | 'postmark' => [ 24 | 'token' => env('POSTMARK_TOKEN'), 25 | ], 26 | 27 | 'ses' => [ 28 | 'key' => env('AWS_ACCESS_KEY_ID'), 29 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 30 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 31 | ], 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /example/config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'file'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Session Lifetime 26 | |-------------------------------------------------------------------------- 27 | | 28 | | Here you may specify the number of minutes that you wish the session 29 | | to be allowed to remain idle before it expires. If you want them 30 | | to immediately expire on the browser closing, set that option. 31 | | 32 | */ 33 | 34 | 'lifetime' => env('SESSION_LIFETIME', 120), 35 | 36 | 'expire_on_close' => false, 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Session Encryption 41 | |-------------------------------------------------------------------------- 42 | | 43 | | This option allows you to easily specify that all of your session data 44 | | should be encrypted before it is stored. All encryption will be run 45 | | automatically by Laravel and you can use the Session like normal. 46 | | 47 | */ 48 | 49 | 'encrypt' => false, 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | Session File Location 54 | |-------------------------------------------------------------------------- 55 | | 56 | | When using the native session driver, we need a location where session 57 | | files may be stored. A default has been set for you but a different 58 | | location may be specified. This is only needed for file sessions. 59 | | 60 | */ 61 | 62 | 'files' => storage_path('framework/sessions'), 63 | 64 | /* 65 | |-------------------------------------------------------------------------- 66 | | Session Database Connection 67 | |-------------------------------------------------------------------------- 68 | | 69 | | When using the "database" or "redis" session drivers, you may specify a 70 | | connection that should be used to manage these sessions. This should 71 | | correspond to a connection in your database configuration options. 72 | | 73 | */ 74 | 75 | 'connection' => env('SESSION_CONNECTION', null), 76 | 77 | /* 78 | |-------------------------------------------------------------------------- 79 | | Session Database Table 80 | |-------------------------------------------------------------------------- 81 | | 82 | | When using the "database" session driver, you may specify the table we 83 | | should use to manage the sessions. Of course, a sensible default is 84 | | provided for you; however, you are free to change this as needed. 85 | | 86 | */ 87 | 88 | 'table' => 'sessions', 89 | 90 | /* 91 | |-------------------------------------------------------------------------- 92 | | Session Cache Store 93 | |-------------------------------------------------------------------------- 94 | | 95 | | While using one of the framework's cache driven session backends you may 96 | | list a cache store that should be used for these sessions. This value 97 | | must match with one of the application's configured cache "stores". 98 | | 99 | | Affects: "apc", "dynamodb", "memcached", "redis" 100 | | 101 | */ 102 | 103 | 'store' => env('SESSION_STORE', null), 104 | 105 | /* 106 | |-------------------------------------------------------------------------- 107 | | Session Sweeping Lottery 108 | |-------------------------------------------------------------------------- 109 | | 110 | | Some session drivers must manually sweep their storage location to get 111 | | rid of old sessions from storage. Here are the chances that it will 112 | | happen on a given request. By default, the odds are 2 out of 100. 113 | | 114 | */ 115 | 116 | 'lottery' => [2, 100], 117 | 118 | /* 119 | |-------------------------------------------------------------------------- 120 | | Session Cookie Name 121 | |-------------------------------------------------------------------------- 122 | | 123 | | Here you may change the name of the cookie used to identify a session 124 | | instance by ID. The name specified here will get used every time a 125 | | new session cookie is created by the framework for every driver. 126 | | 127 | */ 128 | 129 | 'cookie' => env( 130 | 'SESSION_COOKIE', 131 | Str::slug(env('APP_NAME', 'laravel'), '_').'_session' 132 | ), 133 | 134 | /* 135 | |-------------------------------------------------------------------------- 136 | | Session Cookie Path 137 | |-------------------------------------------------------------------------- 138 | | 139 | | The session cookie path determines the path for which the cookie will 140 | | be regarded as available. Typically, this will be the root path of 141 | | your application but you are free to change this when necessary. 142 | | 143 | */ 144 | 145 | 'path' => '/', 146 | 147 | /* 148 | |-------------------------------------------------------------------------- 149 | | Session Cookie Domain 150 | |-------------------------------------------------------------------------- 151 | | 152 | | Here you may change the domain of the cookie used to identify a session 153 | | in your application. This will determine which domains the cookie is 154 | | available to in your application. A sensible default has been set. 155 | | 156 | */ 157 | 158 | 'domain' => env('SESSION_DOMAIN', null), 159 | 160 | /* 161 | |-------------------------------------------------------------------------- 162 | | HTTPS Only Cookies 163 | |-------------------------------------------------------------------------- 164 | | 165 | | By setting this option to true, session cookies will only be sent back 166 | | to the server if the browser has a HTTPS connection. This will keep 167 | | the cookie from being sent to you if it can not be done securely. 168 | | 169 | */ 170 | 171 | 'secure' => env('SESSION_SECURE_COOKIE'), 172 | 173 | /* 174 | |-------------------------------------------------------------------------- 175 | | HTTP Access Only 176 | |-------------------------------------------------------------------------- 177 | | 178 | | Setting this value to true will prevent JavaScript from accessing the 179 | | value of the cookie and the cookie will only be accessible through 180 | | the HTTP protocol. You are free to modify this option if needed. 181 | | 182 | */ 183 | 184 | 'http_only' => true, 185 | 186 | /* 187 | |-------------------------------------------------------------------------- 188 | | Same-Site Cookies 189 | |-------------------------------------------------------------------------- 190 | | 191 | | This option determines how your cookies behave when cross-site requests 192 | | take place, and can be used to mitigate CSRF attacks. By default, we 193 | | will set this value to "lax" since this is a secure default value. 194 | | 195 | | Supported: "lax", "strict", "none", null 196 | | 197 | */ 198 | 199 | 'same_site' => 'lax', 200 | 201 | ]; 202 | -------------------------------------------------------------------------------- /example/config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | resource_path('views'), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => env( 32 | 'VIEW_COMPILED_PATH', 33 | realpath(storage_path('framework/views')) 34 | ), 35 | 36 | ]; 37 | -------------------------------------------------------------------------------- /example/database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | *.sqlite-journal 3 | -------------------------------------------------------------------------------- /example/database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | define(User::class, function (Faker $faker) { 21 | return [ 22 | 'name' => $faker->name, 23 | 'email' => $faker->unique()->safeEmail, 24 | 'email_verified_at' => now(), 25 | 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 26 | 'remember_token' => Str::random(10), 27 | ]; 28 | }); 29 | -------------------------------------------------------------------------------- /example/database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('name'); 19 | $table->string('email')->unique(); 20 | $table->timestamp('email_verified_at')->nullable(); 21 | $table->string('password'); 22 | $table->rememberToken(); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('users'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /example/database/migrations/2019_08_19_000000_create_failed_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->text('connection'); 19 | $table->text('queue'); 20 | $table->longText('payload'); 21 | $table->longText('exception'); 22 | $table->timestamp('failed_at')->useCurrent(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('failed_jobs'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /example/database/seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | call(UserSeeder::class); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "npm run development", 5 | "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 6 | "watch": "npm run development -- --watch", 7 | "watch-poll": "npm run watch -- --watch-poll", 8 | "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js", 9 | "prod": "npm run production", 10 | "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" 11 | }, 12 | "devDependencies": { 13 | "axios": "^0.19", 14 | "cross-env": "^7.0", 15 | "laravel-mix": "^5.0.1", 16 | "lodash": "^4.17.13", 17 | "resolve-url-loader": "^3.1.0", 18 | "sass": "^1.15.2", 19 | "sass-loader": "^8.0.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | ./tests/Unit 10 | 11 | 12 | ./tests/Feature 13 | 14 | 15 | 16 | 17 | ./app 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /example/public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Redirect Trailing Slashes If Not A Folder... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_URI} (.+)/$ 15 | RewriteRule ^ %1 [L,R=301] 16 | 17 | # Send Requests To Front Controller... 18 | RewriteCond %{REQUEST_FILENAME} !-d 19 | RewriteCond %{REQUEST_FILENAME} !-f 20 | RewriteRule ^ index.php [L] 21 | 22 | -------------------------------------------------------------------------------- /example/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverless-components/tencent-laravel/2fa7c2dfbc2955ed12a9e83dcc5c7fdbfde2d309/example/public/favicon.ico -------------------------------------------------------------------------------- /example/public/index.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | define('LARAVEL_START', microtime(true)); 11 | 12 | /* 13 | |-------------------------------------------------------------------------- 14 | | Register The Auto Loader 15 | |-------------------------------------------------------------------------- 16 | | 17 | | Composer provides a convenient, automatically generated class loader for 18 | | our application. We just need to utilize it! We'll simply require it 19 | | into the script here so that we don't have to worry about manual 20 | | loading any of our classes later on. It feels great to relax. 21 | | 22 | */ 23 | 24 | require __DIR__.'/../vendor/autoload.php'; 25 | 26 | /* 27 | |-------------------------------------------------------------------------- 28 | | Turn On The Lights 29 | |-------------------------------------------------------------------------- 30 | | 31 | | We need to illuminate PHP development, so let us turn on the lights. 32 | | This bootstraps the framework and gets it ready for use, then it 33 | | will load up this application so that we can run it and send 34 | | the responses back to the browser and delight our users. 35 | | 36 | */ 37 | 38 | $app = require_once __DIR__.'/../bootstrap/app.php'; 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Run The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once we have the application, we can handle the incoming request 46 | | through the kernel, and send the associated response back to 47 | | the client's browser allowing them to enjoy the creative 48 | | and wonderful application we have prepared for them. 49 | | 50 | */ 51 | 52 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 53 | 54 | $response = $kernel->handle( 55 | $request = Illuminate\Http\Request::capture() 56 | ); 57 | 58 | $response->send(); 59 | 60 | $kernel->terminate($request, $response); 61 | -------------------------------------------------------------------------------- /example/public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /example/public/web.config: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /example/resources/js/app.js: -------------------------------------------------------------------------------- 1 | require('./bootstrap'); 2 | -------------------------------------------------------------------------------- /example/resources/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | window._ = require('lodash'); 2 | 3 | /** 4 | * We'll load the axios HTTP library which allows us to easily issue requests 5 | * to our Laravel back-end. This library automatically handles sending the 6 | * CSRF token as a header based on the value of the "XSRF" token cookie. 7 | */ 8 | 9 | window.axios = require('axios'); 10 | 11 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 12 | 13 | /** 14 | * Echo exposes an expressive API for subscribing to channels and listening 15 | * for events that are broadcast by Laravel. Echo and event broadcasting 16 | * allows your team to easily build robust real-time web applications. 17 | */ 18 | 19 | // import Echo from 'laravel-echo'; 20 | 21 | // window.Pusher = require('pusher-js'); 22 | 23 | // window.Echo = new Echo({ 24 | // broadcaster: 'pusher', 25 | // key: process.env.MIX_PUSHER_APP_KEY, 26 | // cluster: process.env.MIX_PUSHER_APP_CLUSTER, 27 | // forceTLS: true 28 | // }); 29 | -------------------------------------------------------------------------------- /example/resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /example/resources/lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /example/resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Your password has been reset!', 17 | 'sent' => 'We have emailed your password reset link!', 18 | 'throttled' => 'Please wait before retrying.', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that email address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /example/resources/lang/en/validation.php: -------------------------------------------------------------------------------- 1 | 'The :attribute must be accepted.', 17 | 'active_url' => 'The :attribute is not a valid URL.', 18 | 'after' => 'The :attribute must be a date after :date.', 19 | 'after_or_equal' => 'The :attribute must be a date after or equal to :date.', 20 | 'alpha' => 'The :attribute may only contain letters.', 21 | 'alpha_dash' => 'The :attribute may only contain letters, numbers, dashes and underscores.', 22 | 'alpha_num' => 'The :attribute may only contain letters and numbers.', 23 | 'array' => 'The :attribute must be an array.', 24 | 'before' => 'The :attribute must be a date before :date.', 25 | 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', 26 | 'between' => [ 27 | 'numeric' => 'The :attribute must be between :min and :max.', 28 | 'file' => 'The :attribute must be between :min and :max kilobytes.', 29 | 'string' => 'The :attribute must be between :min and :max characters.', 30 | 'array' => 'The :attribute must have between :min and :max items.', 31 | ], 32 | 'boolean' => 'The :attribute field must be true or false.', 33 | 'confirmed' => 'The :attribute confirmation does not match.', 34 | 'date' => 'The :attribute is not a valid date.', 35 | 'date_equals' => 'The :attribute must be a date equal to :date.', 36 | 'date_format' => 'The :attribute does not match the format :format.', 37 | 'different' => 'The :attribute and :other must be different.', 38 | 'digits' => 'The :attribute must be :digits digits.', 39 | 'digits_between' => 'The :attribute must be between :min and :max digits.', 40 | 'dimensions' => 'The :attribute has invalid image dimensions.', 41 | 'distinct' => 'The :attribute field has a duplicate value.', 42 | 'email' => 'The :attribute must be a valid email address.', 43 | 'ends_with' => 'The :attribute must end with one of the following: :values.', 44 | 'exists' => 'The selected :attribute is invalid.', 45 | 'file' => 'The :attribute must be a file.', 46 | 'filled' => 'The :attribute field must have a value.', 47 | 'gt' => [ 48 | 'numeric' => 'The :attribute must be greater than :value.', 49 | 'file' => 'The :attribute must be greater than :value kilobytes.', 50 | 'string' => 'The :attribute must be greater than :value characters.', 51 | 'array' => 'The :attribute must have more than :value items.', 52 | ], 53 | 'gte' => [ 54 | 'numeric' => 'The :attribute must be greater than or equal :value.', 55 | 'file' => 'The :attribute must be greater than or equal :value kilobytes.', 56 | 'string' => 'The :attribute must be greater than or equal :value characters.', 57 | 'array' => 'The :attribute must have :value items or more.', 58 | ], 59 | 'image' => 'The :attribute must be an image.', 60 | 'in' => 'The selected :attribute is invalid.', 61 | 'in_array' => 'The :attribute field does not exist in :other.', 62 | 'integer' => 'The :attribute must be an integer.', 63 | 'ip' => 'The :attribute must be a valid IP address.', 64 | 'ipv4' => 'The :attribute must be a valid IPv4 address.', 65 | 'ipv6' => 'The :attribute must be a valid IPv6 address.', 66 | 'json' => 'The :attribute must be a valid JSON string.', 67 | 'lt' => [ 68 | 'numeric' => 'The :attribute must be less than :value.', 69 | 'file' => 'The :attribute must be less than :value kilobytes.', 70 | 'string' => 'The :attribute must be less than :value characters.', 71 | 'array' => 'The :attribute must have less than :value items.', 72 | ], 73 | 'lte' => [ 74 | 'numeric' => 'The :attribute must be less than or equal :value.', 75 | 'file' => 'The :attribute must be less than or equal :value kilobytes.', 76 | 'string' => 'The :attribute must be less than or equal :value characters.', 77 | 'array' => 'The :attribute must not have more than :value items.', 78 | ], 79 | 'max' => [ 80 | 'numeric' => 'The :attribute may not be greater than :max.', 81 | 'file' => 'The :attribute may not be greater than :max kilobytes.', 82 | 'string' => 'The :attribute may not be greater than :max characters.', 83 | 'array' => 'The :attribute may not have more than :max items.', 84 | ], 85 | 'mimes' => 'The :attribute must be a file of type: :values.', 86 | 'mimetypes' => 'The :attribute must be a file of type: :values.', 87 | 'min' => [ 88 | 'numeric' => 'The :attribute must be at least :min.', 89 | 'file' => 'The :attribute must be at least :min kilobytes.', 90 | 'string' => 'The :attribute must be at least :min characters.', 91 | 'array' => 'The :attribute must have at least :min items.', 92 | ], 93 | 'not_in' => 'The selected :attribute is invalid.', 94 | 'not_regex' => 'The :attribute format is invalid.', 95 | 'numeric' => 'The :attribute must be a number.', 96 | 'password' => 'The password is incorrect.', 97 | 'present' => 'The :attribute field must be present.', 98 | 'regex' => 'The :attribute format is invalid.', 99 | 'required' => 'The :attribute field is required.', 100 | 'required_if' => 'The :attribute field is required when :other is :value.', 101 | 'required_unless' => 'The :attribute field is required unless :other is in :values.', 102 | 'required_with' => 'The :attribute field is required when :values is present.', 103 | 'required_with_all' => 'The :attribute field is required when :values are present.', 104 | 'required_without' => 'The :attribute field is required when :values is not present.', 105 | 'required_without_all' => 'The :attribute field is required when none of :values are present.', 106 | 'same' => 'The :attribute and :other must match.', 107 | 'size' => [ 108 | 'numeric' => 'The :attribute must be :size.', 109 | 'file' => 'The :attribute must be :size kilobytes.', 110 | 'string' => 'The :attribute must be :size characters.', 111 | 'array' => 'The :attribute must contain :size items.', 112 | ], 113 | 'starts_with' => 'The :attribute must start with one of the following: :values.', 114 | 'string' => 'The :attribute must be a string.', 115 | 'timezone' => 'The :attribute must be a valid zone.', 116 | 'unique' => 'The :attribute has already been taken.', 117 | 'uploaded' => 'The :attribute failed to upload.', 118 | 'url' => 'The :attribute format is invalid.', 119 | 'uuid' => 'The :attribute must be a valid UUID.', 120 | 121 | /* 122 | |-------------------------------------------------------------------------- 123 | | Custom Validation Language Lines 124 | |-------------------------------------------------------------------------- 125 | | 126 | | Here you may specify custom validation messages for attributes using the 127 | | convention "attribute.rule" to name the lines. This makes it quick to 128 | | specify a specific custom language line for a given attribute rule. 129 | | 130 | */ 131 | 132 | 'custom' => [ 133 | 'attribute-name' => [ 134 | 'rule-name' => 'custom-message', 135 | ], 136 | ], 137 | 138 | /* 139 | |-------------------------------------------------------------------------- 140 | | Custom Validation Attributes 141 | |-------------------------------------------------------------------------- 142 | | 143 | | The following language lines are used to swap our attribute placeholder 144 | | with something more reader friendly such as "E-Mail Address" instead 145 | | of "email". This simply helps us make our message more expressive. 146 | | 147 | */ 148 | 149 | 'attributes' => [], 150 | 151 | ]; 152 | -------------------------------------------------------------------------------- /example/resources/sass/app.scss: -------------------------------------------------------------------------------- 1 | // 2 | -------------------------------------------------------------------------------- /example/resources/views/welcome.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Laravel 8 | 9 | 10 | 11 | 12 | 13 | 65 | 66 | 67 |
68 | @if (Route::has('login')) 69 | 80 | @endif 81 | 82 |
83 |
84 | Laravel 85 |
86 | 87 | 97 |
98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /example/routes/api.php: -------------------------------------------------------------------------------- 1 | get('/user', function (Request $request) { 18 | return $request->user(); 19 | }); 20 | 21 | Route::get('/posts', function (Request $request) { 22 | $input = $request->all(); 23 | 24 | return response()->json([ 25 | 'title' => 'serverless', 26 | 'get' => $input 27 | ]); 28 | }); 29 | 30 | Route::post('/posts', function (Request $request) { 31 | $input = $request->all(); 32 | 33 | return response()->json([ 34 | 'title' => 'serverless', 35 | 'data' => $input 36 | ]); 37 | }); 38 | 39 | // 上传文件接口示例 40 | Route::post('/upload', function (Request $request) { 41 | // 表单中字段为 file 42 | if ($request->file) { 43 | // TODO: 这里只是将文件临时存储到 /tmp 下,用户需要根据个人需要存储到持久化服务,比如腾讯云的对象存储、文件存储等。 44 | $upload = $request->file->store('upload'); 45 | $uploadFile = storage_path()."/app/".$upload; 46 | } 47 | 48 | return response()->json([ 49 | 'title' => 'serverless', 50 | 'upload' => $uploadFile ?? null, 51 | ]); 52 | }); 53 | -------------------------------------------------------------------------------- /example/routes/channels.php: -------------------------------------------------------------------------------- 1 | id === (int) $id; 18 | }); 19 | -------------------------------------------------------------------------------- /example/routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 19 | })->describe('Display an inspiring quote'); 20 | -------------------------------------------------------------------------------- /example/routes/web.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /example/serverless.yml: -------------------------------------------------------------------------------- 1 | app: appDemo 2 | stage: dev 3 | component: laravel 4 | name: laravelDemo 5 | 6 | inputs: 7 | src: 8 | src: ./ 9 | region: ap-guangzhou 10 | runtime: Php7 11 | apigatewayConf: 12 | protocols: 13 | - http 14 | - https 15 | environment: release 16 | -------------------------------------------------------------------------------- /example/webpack.mix.js: -------------------------------------------------------------------------------- 1 | const mix = require('laravel-mix'); 2 | 3 | /* 4 | |-------------------------------------------------------------------------- 5 | | Mix Asset Management 6 | |-------------------------------------------------------------------------- 7 | | 8 | | Mix provides a clean, fluent API for defining some Webpack build steps 9 | | for your Laravel application. By default, we are compiling the Sass 10 | | file for the application as well as bundling up all the JS files. 11 | | 12 | */ 13 | 14 | mix.js('resources/js/app.js', 'public/js') 15 | .sass('resources/sass/app.scss', 'public/css'); 16 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | const { join } = require('path') 2 | require('dotenv').config({ path: join(__dirname, '.env.test') }) 3 | 4 | const config = { 5 | verbose: true, 6 | silent: false, 7 | testTimeout: 600000, 8 | testEnvironment: 'node', 9 | testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js|ts)$', 10 | testPathIgnorePatterns: ['/node_modules/', '/__tests__/lib/'], 11 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] 12 | } 13 | 14 | module.exports = config 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@serverless/laravel", 3 | "description": "Tencent Cloud Laravel Serverless Component", 4 | "main": "src/serverless.js", 5 | "publishConfig": { 6 | "access": "public" 7 | }, 8 | "scripts": { 9 | "test": "jest", 10 | "commitlint": "commitlint -f HEAD@{15}", 11 | "lint": "eslint --ext .js,.ts,.tsx .", 12 | "lint:fix": "eslint --fix --ext .js,.ts,.tsx .", 13 | "prettier": "prettier --check '**/*.{css,html,js,json,md,yaml,yml}'", 14 | "prettier:fix": "prettier --write '**/*.{css,html,js,json,md,yaml,yml}'", 15 | "release": "semantic-release", 16 | "release-local": "node -r dotenv/config node_modules/semantic-release/bin/semantic-release --no-ci --dry-run", 17 | "check-dependencies": "npx npm-check --skip-unused --update" 18 | }, 19 | "husky": { 20 | "hooks": { 21 | "pre-commit": "ygsec && lint-staged", 22 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", 23 | "pre-push": "ygsec && npm run lint:fix && npm run prettier:fix" 24 | } 25 | }, 26 | "lint-staged": { 27 | "**/*.{js,ts,tsx}": [ 28 | "npm run lint:fix", 29 | "git add ." 30 | ], 31 | "**/*.{css,html,js,json,md,yaml,yml}": [ 32 | "npm run prettier:fix", 33 | "git add ." 34 | ] 35 | }, 36 | "author": "Tencent Cloud, Inc.", 37 | "license": "MIT", 38 | "dependencies": {}, 39 | "devDependencies": { 40 | "@commitlint/cli": "^8.3.5", 41 | "@commitlint/config-conventional": "^8.3.4", 42 | "@semantic-release/changelog": "^5.0.0", 43 | "@semantic-release/commit-analyzer": "^8.0.1", 44 | "@semantic-release/git": "^9.0.0", 45 | "@semantic-release/npm": "^7.0.4", 46 | "@semantic-release/release-notes-generator": "^9.0.1", 47 | "@serverless/platform-client-china": "^1.0.19", 48 | "@ygkit/secure": "0.0.3", 49 | "axios": "^0.19.2", 50 | "babel-eslint": "^10.1.0", 51 | "dotenv": "^8.2.0", 52 | "eslint": "^6.8.0", 53 | "eslint-config-prettier": "^6.10.0", 54 | "eslint-plugin-import": "^2.20.1", 55 | "eslint-plugin-prettier": "^3.1.2", 56 | "husky": "^4.2.5", 57 | "jest": "^25.0.1", 58 | "lint-staged": "^10.0.8", 59 | "prettier": "^1.19.1", 60 | "semantic-release": "^17.0.4" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'always', 3 | printWidth: 100, 4 | semi: false, 5 | singleQuote: true, 6 | tabWidth: 2, 7 | trailingComma: 'none' 8 | } 9 | -------------------------------------------------------------------------------- /release.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | verifyConditions: [ 3 | '@semantic-release/changelog', 4 | '@semantic-release/git', 5 | '@semantic-release/github' 6 | ], 7 | plugins: [ 8 | [ 9 | '@semantic-release/commit-analyzer', 10 | { 11 | preset: 'angular', 12 | parserOpts: { 13 | noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING'] 14 | } 15 | } 16 | ], 17 | [ 18 | '@semantic-release/release-notes-generator', 19 | { 20 | preset: 'angular', 21 | parserOpts: { 22 | noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING'] 23 | }, 24 | writerOpts: { 25 | commitsSort: ['subject', 'scope'] 26 | } 27 | } 28 | ], 29 | [ 30 | '@semantic-release/changelog', 31 | { 32 | changelogFile: 'CHANGELOG.md' 33 | } 34 | ], 35 | [ 36 | '@semantic-release/git', 37 | { 38 | assets: ['package.json', 'src/**', 'CHANGELOG.md'], 39 | message: 'chore(release): version ${nextRelease.version} \n\n${nextRelease.notes}' 40 | } 41 | ], 42 | [ 43 | '@semantic-release/github', 44 | { 45 | assets: ['!.env'] 46 | } 47 | ] 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /serverless.component.yml: -------------------------------------------------------------------------------- 1 | name: laravel 2 | version: 0.2.1 3 | author: 'Tencent Cloud, Inc' 4 | org: 'Tencent Cloud, Inc' 5 | description: Deploy a serverless Laravel application on Tencent SCF and API Gateway. 6 | keywords: 'tencent, serverless, laravel' 7 | repo: 'https://github.com/serverless-components/tencent-laravel' 8 | readme: 'https://github.com/serverless-components/tencent-laravel/tree/master/README.md' 9 | license: MIT 10 | main: ./src 11 | webDeployable: true 12 | -------------------------------------------------------------------------------- /src/_shims/sl_handler.php: -------------------------------------------------------------------------------- 1 | '', 32 | 'Cache-Control' => "max-age=8640000", 33 | 'Accept-Ranges' => 'bytes', 34 | ]; 35 | $body = $contents; 36 | if ($isBase64Encoded || preg_match(BINARY_REG, $path)) { 37 | $base64Encode = true; 38 | $headers = [ 39 | 'Content-Type' => '', 40 | 'Cache-Control' => "max-age=86400", 41 | ]; 42 | $body = base64_encode($contents); 43 | } 44 | return [ 45 | "isBase64Encoded" => $base64Encode, 46 | "statusCode" => 200, 47 | "headers" => $headers, 48 | "body" => $body, 49 | ]; 50 | } 51 | 52 | function initEnvironment($isBase64Encoded) 53 | { 54 | $envName = ''; 55 | if (file_exists(__DIR__ . "/.env")) { 56 | $envName = '.env'; 57 | } elseif (file_exists(__DIR__ . "/.env.production")) { 58 | $envName = '.env.production'; 59 | } elseif (file_exists(__DIR__ . "/.env.local")) { 60 | $envName = ".env.local"; 61 | } 62 | if (!$envName) { 63 | return [ 64 | 'isBase64Encoded' => $isBase64Encoded, 65 | 'statusCode' => 500, 66 | 'headers' => [ 67 | 'Content-Type' => 'application/json' 68 | ], 69 | 'body' => $isBase64Encoded ? base64_encode([ 70 | 'error' => "Dotenv config file not exist" 71 | ]) : [ 72 | 'error' => "Dotenv config file not exist" 73 | ] 74 | ]; 75 | } 76 | 77 | $dotenv = Dotenv\Dotenv::createImmutable(__DIR__, $envName); 78 | $dotenv->load(); 79 | } 80 | 81 | function decodeFormData($rawData) 82 | { 83 | $files = array(); 84 | $data = array(); 85 | $boundary = substr($rawData, 0, strpos($rawData, "\r\n")); 86 | // Fetch and process each part 87 | $parts = array_slice(explode($boundary, $rawData), 1); 88 | foreach ($parts as $part) { 89 | // If this is the last part, break 90 | if ($part == "--\r\n") { 91 | break; 92 | } 93 | // Separate content from headers 94 | $part = ltrim($part, "\r\n"); 95 | list($rawHeaders, $content) = explode("\r\n\r\n", $part, 2); 96 | $content = substr($content, 0, strlen($content) - 2); 97 | // Parse the headers list 98 | $rawHeaders = explode("\r\n", $rawHeaders); 99 | $headers = array(); 100 | foreach ($rawHeaders as $header) { 101 | list($name, $value) = explode(':', $header); 102 | $headers[strtolower($name)] = ltrim($value, ' '); 103 | } 104 | // Parse the Content-Disposition to get the field name, etc. 105 | if (isset($headers['content-disposition'])) { 106 | $filename = null; 107 | preg_match('/^form-data; *name="([^"]+)"(; *filename="([^"]+)")?/', $headers['content-disposition'], $matches); 108 | $fieldName = $matches[1]; 109 | $fileName = (isset($matches[3]) ? $matches[3] : null); 110 | // consoleLog('Upload Filename', $fileName); 111 | // If we have a file, save it. Otherwise, save the data. 112 | if ($fileName !== null) { 113 | $localFileName = tempnam('/tmp', 'sfy'); 114 | file_put_contents($localFileName, $content); 115 | 116 | $arr = array( 117 | 'name' => $fileName, 118 | 'type' => $headers['content-type'], 119 | 'tmp_name' => $localFileName, 120 | 'error' => 0, 121 | 'size' => filesize($localFileName) 122 | ); 123 | 124 | if (substr($fieldName, -2, 2) == '[]') { 125 | $fieldName = substr($fieldName, 0, strlen($fieldName) - 2); 126 | } 127 | 128 | if (array_key_exists($fieldName, $files)) { 129 | array_push($files[$fieldName], $arr); 130 | } else { 131 | $files[$fieldName] = $arr; 132 | } 133 | 134 | // register a shutdown function to cleanup the temporary file 135 | register_shutdown_function(function () use ($localFileName) { 136 | unlink($localFileName); 137 | }); 138 | } else { 139 | parse_str($fieldName . '=__INPUT__', $parsedInput); 140 | $dottedInput = Arr::dot($parsedInput); 141 | $targetInput = Arr::add([], array_keys($dottedInput)[0], $content); 142 | 143 | $data = array_merge_recursive($data, $targetInput); 144 | } 145 | } 146 | } 147 | return (object)([ 148 | 'data' => $data, 149 | 'files' => $files 150 | ]); 151 | } 152 | 153 | function handler($event, $context) 154 | { 155 | require __DIR__ . '/vendor/autoload.php'; 156 | 157 | $isBase64Encoded = $event->isBase64Encoded; 158 | 159 | 160 | initEnvironment($isBase64Encoded); 161 | 162 | $app = require __DIR__ . '/bootstrap/app.php'; 163 | 164 | // change storage path to APP_STORAGE in dotenv 165 | $app->useStoragePath( env( 'APP_STORAGE', base_path() . '/storage' ) ); 166 | 167 | 168 | // init path 169 | $path = str_replace("//", "/", $event->path); 170 | 171 | if (preg_match(TEXT_REG, $path) || preg_match(BINARY_REG, $path)) { 172 | return handlerStatic($path, $isBase64Encoded); 173 | } 174 | 175 | // init headers 176 | $headers = $event->headers ?? []; 177 | $headers = json_decode(json_encode($headers), true); 178 | 179 | // consoleLog("Event", $event); 180 | 181 | // init request data 182 | $data = []; 183 | $rawBody = $event->body ?? null; 184 | if ($event->httpMethod === 'GET') { 185 | $data = !empty($event->queryString) ? $event->queryString : []; 186 | } else { 187 | if ($isBase64Encoded) { 188 | $rawBody = base64_decode($rawBody); 189 | } 190 | $contentType = $headers['Content-Type'] ?? $headers['content-type']; 191 | if (preg_match('/multipart\/form-data/', $contentType)) { 192 | $requestData = !empty($rawBody) ? decodeFormData($rawBody) : []; 193 | consoleLog('Post File', $requestData); 194 | $data = $requestData->data; 195 | $files = $requestData->files; 196 | } else if (preg_match('/application\/x-www-form-urlencoded/', $contentType)) { 197 | if (!empty($rawBody)) { 198 | mb_parse_str($rawBody, $data); 199 | } 200 | } else { 201 | $data = !empty($rawBody) ? json_decode($rawBody, true) : []; 202 | } 203 | } 204 | 205 | // consoleLog('Request Data', $data); 206 | // consoleLog('Raw Body', $rawBody); 207 | 208 | // execute laravel app request, get response 209 | $kernel = $app->make(Kernel::class); 210 | 211 | $request = Request::create($path, $event->httpMethod, (array) $data, [], [], $headers, $rawBody); 212 | if (!empty($files)) { 213 | $request->files->add($files); 214 | } 215 | $response = $kernel->handle( 216 | $request 217 | ); 218 | 219 | // init content 220 | $body = $response->getContent(); 221 | $contentType = $response->headers->get('Content-Type'); 222 | 223 | return [ 224 | 'isBase64Encoded' => $isBase64Encoded, 225 | 'statusCode' => $response->getStatusCode() ?? 200, 226 | 'headers' => [ 227 | 'Content-Type' => $contentType 228 | ], 229 | 'body' => $isBase64Encoded ? base64_encode(($body)) : $body 230 | ]; 231 | } 232 | -------------------------------------------------------------------------------- /src/config.js: -------------------------------------------------------------------------------- 1 | const CONFIGS = { 2 | templateUrl: 3 | 'https://serverless-templates-1300862921.cos.ap-beijing.myqcloud.com/laravel-demo.zip', 4 | compName: 'laravel', 5 | compFullname: 'Laravel', 6 | handler: 'sl_handler.handler', 7 | runtime: 'Php7', 8 | exclude: ['.git/**', '.gitignore', '.DS_Store'], 9 | timeout: 3, 10 | memorySize: 128, 11 | namespace: 'default', 12 | description: 'Created by Serverless Component', 13 | defaultEnvs: { 14 | SERVERLESS: '1', 15 | VIEW_COMPILED_PATH: '/tmp/storage/framework/views', 16 | SESSION_DRIVER: 'array', 17 | LOG_CHANNEL: 'stderr', 18 | APP_STORAGE: '/tmp' 19 | } 20 | } 21 | 22 | module.exports = CONFIGS 23 | -------------------------------------------------------------------------------- /src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "download": "^8.0.0", 4 | "tencent-component-toolkit": "^2.2.0", 5 | "type": "^2.1.0" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/serverless.js: -------------------------------------------------------------------------------- 1 | const { Component } = require('@serverless/core') 2 | const { Scf, Apigw } = require('tencent-component-toolkit') 3 | const { ApiTypeError } = require('tencent-component-toolkit/lib/utils/error') 4 | const { uploadCodeToCos, getDefaultProtocol, prepareInputs, deepClone } = require('./utils') 5 | const CONFIGS = require('./config') 6 | 7 | class ServerlessComponent extends Component { 8 | getCredentials() { 9 | const { tmpSecrets } = this.credentials.tencent 10 | 11 | if (!tmpSecrets || !tmpSecrets.TmpSecretId) { 12 | throw new ApiTypeError( 13 | 'CREDENTIAL', 14 | 'Cannot get secretId/Key, your account could be sub-account and does not have the access to use SLS_QcsRole, please make sure the role exists first, then visit https://cloud.tencent.com/document/product/1154/43006, follow the instructions to bind the role to your account.' 15 | ) 16 | } 17 | 18 | return { 19 | SecretId: tmpSecrets.TmpSecretId, 20 | SecretKey: tmpSecrets.TmpSecretKey, 21 | Token: tmpSecrets.Token 22 | } 23 | } 24 | 25 | getAppId() { 26 | return this.credentials.tencent.tmpSecrets.appId 27 | } 28 | 29 | async deployFunction(credentials, inputs, regionList) { 30 | const outputs = {} 31 | const appId = this.getAppId() 32 | 33 | const funcDeployer = async (curRegion) => { 34 | const code = await uploadCodeToCos(this, appId, credentials, inputs, curRegion) 35 | const scf = new Scf(credentials, curRegion) 36 | const tempInputs = { 37 | ...inputs, 38 | code 39 | } 40 | const scfOutput = await scf.deploy(deepClone(tempInputs)) 41 | outputs[curRegion] = { 42 | functionName: scfOutput.FunctionName, 43 | runtime: scfOutput.Runtime, 44 | namespace: scfOutput.Namespace 45 | } 46 | 47 | this.state[curRegion] = { 48 | ...(this.state[curRegion] ? this.state[curRegion] : {}), 49 | ...outputs[curRegion] 50 | } 51 | 52 | // default version is $LATEST 53 | outputs[curRegion].lastVersion = scfOutput.LastVersion 54 | ? scfOutput.LastVersion 55 | : this.state.lastVersion || '$LATEST' 56 | 57 | // default traffic is 1.0, it can also be 0, so we should compare to undefined 58 | outputs[curRegion].traffic = 59 | scfOutput.Traffic !== undefined 60 | ? scfOutput.Traffic 61 | : this.state.traffic !== undefined 62 | ? this.state.traffic 63 | : 1 64 | 65 | if (outputs[curRegion].traffic !== 1 && scfOutput.ConfigTrafficVersion) { 66 | outputs[curRegion].configTrafficVersion = scfOutput.ConfigTrafficVersion 67 | this.state.configTrafficVersion = scfOutput.ConfigTrafficVersion 68 | } 69 | 70 | this.state.lastVersion = outputs[curRegion].lastVersion 71 | this.state.traffic = outputs[curRegion].traffic 72 | } 73 | 74 | for (let i = 0; i < regionList.length; i++) { 75 | const curRegion = regionList[i] 76 | await funcDeployer(curRegion) 77 | } 78 | this.save() 79 | return outputs 80 | } 81 | 82 | async deployApigateway(credentials, inputs, regionList) { 83 | if (inputs.isDisabled) { 84 | return {} 85 | } 86 | 87 | const getServiceId = (instance, region) => { 88 | const regionState = instance.state[region] 89 | return inputs.serviceId || (regionState && regionState.serviceId) 90 | } 91 | 92 | const deployTasks = [] 93 | const outputs = {} 94 | regionList.forEach((curRegion) => { 95 | const apigwDeployer = async () => { 96 | const apigw = new Apigw(credentials, curRegion) 97 | 98 | const oldState = this.state[curRegion] || {} 99 | const apigwInputs = { 100 | ...inputs, 101 | oldState: { 102 | apiList: oldState.apiList || [], 103 | customDomains: oldState.customDomains || [] 104 | } 105 | } 106 | // different region deployment has different service id 107 | apigwInputs.serviceId = getServiceId(this, curRegion) 108 | const apigwOutput = await apigw.deploy(deepClone(apigwInputs)) 109 | outputs[curRegion] = { 110 | serviceId: apigwOutput.serviceId, 111 | subDomain: apigwOutput.subDomain, 112 | environment: apigwOutput.environment, 113 | url: `${getDefaultProtocol(inputs.protocols)}://${apigwOutput.subDomain}/${ 114 | apigwOutput.environment 115 | }/` 116 | } 117 | 118 | if (apigwOutput.customDomains) { 119 | outputs[curRegion].customDomains = apigwOutput.customDomains 120 | } 121 | this.state[curRegion] = { 122 | created: true, 123 | ...(this.state[curRegion] ? this.state[curRegion] : {}), 124 | ...outputs[curRegion], 125 | apiList: apigwOutput.apiList 126 | } 127 | } 128 | deployTasks.push(apigwDeployer()) 129 | }) 130 | 131 | await Promise.all(deployTasks) 132 | 133 | this.save() 134 | return outputs 135 | } 136 | 137 | async deploy(inputs) { 138 | console.log(`Deploying ${CONFIGS.compFullname} App...`) 139 | 140 | const credentials = this.getCredentials() 141 | 142 | // 对Inputs内容进行标准化 143 | const { regionList, functionConf, apigatewayConf } = await prepareInputs( 144 | this, 145 | credentials, 146 | inputs 147 | ) 148 | 149 | // 部署函数 + API网关 150 | const outputs = {} 151 | if (!functionConf.code.src) { 152 | outputs.templateUrl = CONFIGS.templateUrl 153 | } 154 | 155 | let apigwOutputs 156 | const functionOutputs = await this.deployFunction( 157 | credentials, 158 | functionConf, 159 | regionList, 160 | outputs 161 | ) 162 | // support apigatewayConf.isDisabled 163 | if (apigatewayConf.isDisabled !== true) { 164 | apigwOutputs = await this.deployApigateway(credentials, apigatewayConf, regionList, outputs) 165 | } else { 166 | this.state.apigwDisabled = true 167 | } 168 | 169 | // optimize outputs for one region 170 | if (regionList.length === 1) { 171 | const [oneRegion] = regionList 172 | outputs.region = oneRegion 173 | outputs['scf'] = functionOutputs[oneRegion] 174 | if (apigwOutputs) { 175 | outputs['apigw'] = apigwOutputs[oneRegion] 176 | } 177 | } else { 178 | outputs['scf'] = functionOutputs 179 | if (apigwOutputs) { 180 | outputs['apigw'] = apigwOutputs 181 | } 182 | } 183 | 184 | this.state.region = regionList[0] 185 | this.state.regionList = regionList 186 | this.state.lambdaArn = functionConf.name 187 | 188 | return outputs 189 | } 190 | 191 | async remove() { 192 | console.log(`Removing ${CONFIGS.compFullname} App...`) 193 | 194 | const { state } = this 195 | const { regionList = [] } = state 196 | 197 | const credentials = this.getCredentials() 198 | 199 | const removeHandlers = [] 200 | for (let i = 0; i < regionList.length; i++) { 201 | const curRegion = regionList[i] 202 | const curState = state[curRegion] 203 | const scf = new Scf(credentials, curRegion) 204 | const apigw = new Apigw(credentials, curRegion) 205 | const handler = async () => { 206 | // if disable apigw, no need to remove 207 | if (state.apigwDisabled !== true) { 208 | await apigw.remove({ 209 | created: curState.created, 210 | environment: curState.environment, 211 | serviceId: curState.serviceId, 212 | apiList: curState.apiList, 213 | customDomains: curState.customDomains 214 | }) 215 | } 216 | await scf.remove({ 217 | functionName: curState.functionName, 218 | namespace: curState.namespace 219 | }) 220 | } 221 | removeHandlers.push(handler()) 222 | } 223 | 224 | await Promise.all(removeHandlers) 225 | 226 | this.state = {} 227 | } 228 | } 229 | 230 | module.exports = ServerlessComponent 231 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const fs = require('fs') 3 | const { Cos } = require('tencent-component-toolkit') 4 | const ensureObject = require('type/object/ensure') 5 | const ensureIterable = require('type/iterable/ensure') 6 | const ensureString = require('type/string/ensure') 7 | const download = require('download') 8 | const { ApiTypeError } = require('tencent-component-toolkit/lib/utils/error') 9 | const CONFIGS = require('./config') 10 | 11 | /* 12 | * Generates a random id 13 | */ 14 | const generateId = () => 15 | Math.random() 16 | .toString(36) 17 | .substring(6) 18 | 19 | const deepClone = (obj) => { 20 | return JSON.parse(JSON.stringify(obj)) 21 | } 22 | 23 | const getType = (obj) => { 24 | return Object.prototype.toString.call(obj).slice(8, -1) 25 | } 26 | 27 | const mergeJson = (sourceJson, targetJson) => { 28 | Object.entries(sourceJson).forEach(([key, val]) => { 29 | targetJson[key] = deepClone(val) 30 | }) 31 | return targetJson 32 | } 33 | 34 | const capitalString = (str) => { 35 | if (str.length < 2) { 36 | return str.toUpperCase() 37 | } 38 | 39 | return `${str[0].toUpperCase()}${str.slice(1)}` 40 | } 41 | 42 | const getDefaultProtocol = (protocols) => { 43 | return String(protocols).includes('https') ? 'https' : 'http' 44 | } 45 | 46 | const getDefaultFunctionName = () => { 47 | return `${CONFIGS.compName}_component_${generateId()}` 48 | } 49 | 50 | const getDefaultServiceName = () => { 51 | return 'serverless' 52 | } 53 | 54 | const getDefaultServiceDescription = () => { 55 | return 'Created by Serverless Component' 56 | } 57 | 58 | const validateTraffic = (num) => { 59 | if (getType(num) !== 'Number') { 60 | throw new ApiTypeError( 61 | `PARAMETER_${CONFIGS.compName.toUpperCase()}_TRAFFIC`, 62 | 'traffic must be a number' 63 | ) 64 | } 65 | if (num < 0 || num > 1) { 66 | throw new ApiTypeError( 67 | `PARAMETER_${CONFIGS.compName.toUpperCase()}_TRAFFIC`, 68 | 'traffic must be a number between 0 and 1' 69 | ) 70 | } 71 | return true 72 | } 73 | 74 | const getCodeZipPath = async (instance, inputs) => { 75 | console.log(`Packaging ${CONFIGS.compFullname} application...`) 76 | 77 | // unzip source zip file 78 | let zipPath 79 | if (!inputs.code.src) { 80 | // add default template 81 | const downloadPath = `/tmp/${generateId()}` 82 | const filename = 'template' 83 | 84 | console.log(`Installing Default ${CONFIGS.compFullname} App...`) 85 | try { 86 | await download(CONFIGS.templateUrl, downloadPath, { 87 | filename: `${filename}.zip` 88 | }) 89 | } catch (e) { 90 | throw new ApiTypeError(`DOWNLOAD_TEMPLATE`, 'Download default template failed.') 91 | } 92 | zipPath = `${downloadPath}/${filename}.zip` 93 | } else { 94 | zipPath = inputs.code.src 95 | } 96 | 97 | return zipPath 98 | } 99 | 100 | const getDirFiles = async (dirPath) => { 101 | const targetPath = path.resolve(dirPath) 102 | const files = fs.readdirSync(targetPath) 103 | const temp = {} 104 | files.forEach((file) => { 105 | temp[file] = path.join(targetPath, file) 106 | }) 107 | return temp 108 | } 109 | 110 | /** 111 | * Upload code to COS 112 | * @param {Component} instance serverless component instance 113 | * @param {string} appId app id 114 | * @param {object} credentials credentials 115 | * @param {object} inputs component inputs parameters 116 | * @param {string} region region 117 | */ 118 | const uploadCodeToCos = async (instance, appId, credentials, inputs, region) => { 119 | const bucketName = inputs.code.bucket || `sls-cloudfunction-${region}-code` 120 | const objectName = inputs.code.object || `${inputs.name}-${Math.floor(Date.now() / 1000)}.zip` 121 | // if set bucket and object not pack code 122 | if (!inputs.code.bucket || !inputs.code.object) { 123 | const zipPath = await getCodeZipPath(instance, inputs) 124 | console.log(`Code zip path ${zipPath}`) 125 | 126 | // save the zip path to state for lambda to use it 127 | instance.state.zipPath = zipPath 128 | 129 | const cos = new Cos(credentials, region) 130 | 131 | if (!inputs.code.bucket) { 132 | // create default bucket 133 | await cos.deploy({ 134 | bucket: bucketName + '-' + appId, 135 | force: true, 136 | lifecycle: [ 137 | { 138 | status: 'Enabled', 139 | id: 'deleteObject', 140 | filter: '', 141 | expiration: { days: '10' }, 142 | abortIncompleteMultipartUpload: { daysAfterInitiation: '10' } 143 | } 144 | ] 145 | }) 146 | } 147 | 148 | // upload code to cos 149 | if (!inputs.code.object) { 150 | console.log(`Getting cos upload url for bucket ${bucketName}`) 151 | const uploadUrl = await cos.getObjectUrl({ 152 | bucket: bucketName + '-' + appId, 153 | object: objectName, 154 | method: 'PUT' 155 | }) 156 | 157 | // if shims and sls sdk entries had been injected to zipPath, no need to injected again 158 | console.log(`Uploading code to bucket ${bucketName}`) 159 | if (instance.codeInjected === true) { 160 | await instance.uploadSourceZipToCOS(zipPath, uploadUrl, {}, {}) 161 | } else { 162 | const shimFiles = await getDirFiles(path.join(__dirname, '_shims')) 163 | await instance.uploadSourceZipToCOS(zipPath, uploadUrl, shimFiles, {}) 164 | instance.codeInjected = true 165 | } 166 | console.log(`Upload ${objectName} to bucket ${bucketName} success`) 167 | } 168 | } 169 | 170 | // save bucket state 171 | instance.state.bucket = bucketName 172 | instance.state.object = objectName 173 | 174 | return { 175 | bucket: bucketName, 176 | object: objectName 177 | } 178 | } 179 | 180 | const prepareInputs = async (instance, credentials, inputs = {}) => { 181 | // 对function inputs进行标准化 182 | const tempFunctionConf = inputs.functionConf 183 | ? inputs.functionConf 184 | : inputs.functionConfig 185 | ? inputs.functionConfig 186 | : {} 187 | const fromClientRemark = `tencent-${CONFIGS.compName}` 188 | const regionList = inputs.region 189 | ? typeof inputs.region == 'string' 190 | ? [inputs.region] 191 | : inputs.region 192 | : ['ap-guangzhou'] 193 | 194 | // chenck state function name 195 | const stateFunctionName = 196 | instance.state[regionList[0]] && instance.state[regionList[0]].functionName 197 | const functionConf = Object.assign(tempFunctionConf, { 198 | code: { 199 | src: inputs.src, 200 | bucket: inputs.srcOriginal && inputs.srcOriginal.bucket, 201 | object: inputs.srcOriginal && inputs.srcOriginal.object 202 | }, 203 | name: 204 | tempFunctionConf.name || inputs.functionName || stateFunctionName || getDefaultFunctionName(), 205 | region: regionList, 206 | role: ensureString(tempFunctionConf.role ? tempFunctionConf.role : inputs.role, { 207 | default: '' 208 | }), 209 | handler: ensureString(tempFunctionConf.handler ? tempFunctionConf.handler : inputs.handler, { 210 | default: CONFIGS.handler 211 | }), 212 | runtime: ensureString(tempFunctionConf.runtime ? tempFunctionConf.runtime : inputs.runtime, { 213 | default: CONFIGS.runtime 214 | }), 215 | namespace: ensureString( 216 | tempFunctionConf.namespace ? tempFunctionConf.namespace : inputs.namespace, 217 | { default: CONFIGS.namespace } 218 | ), 219 | description: ensureString( 220 | tempFunctionConf.description ? tempFunctionConf.description : inputs.description, 221 | { 222 | default: CONFIGS.description 223 | } 224 | ), 225 | fromClientRemark, 226 | layers: ensureIterable(tempFunctionConf.layers ? tempFunctionConf.layers : inputs.layers, { 227 | default: [] 228 | }), 229 | cfs: ensureIterable(tempFunctionConf.cfs ? tempFunctionConf.cfs : inputs.cfs, { 230 | default: [] 231 | }), 232 | publish: inputs.publish, 233 | traffic: inputs.traffic, 234 | lastVersion: instance.state.lastVersion, 235 | timeout: tempFunctionConf.timeout || CONFIGS.timeout, 236 | memorySize: tempFunctionConf.memorySize || CONFIGS.memorySize, 237 | tags: ensureObject(tempFunctionConf.tags ? tempFunctionConf.tags : inputs.tags, { 238 | default: null 239 | }) 240 | }) 241 | 242 | // validate traffic 243 | if (inputs.traffic !== undefined) { 244 | validateTraffic(inputs.traffic) 245 | } 246 | functionConf.needSetTraffic = inputs.traffic !== undefined && functionConf.lastVersion 247 | 248 | if (tempFunctionConf.environment) { 249 | functionConf.environment = tempFunctionConf.environment 250 | functionConf.environment.variables = { 251 | ...(functionConf.environment.variables || {}), 252 | ...CONFIGS.defaultEnvs 253 | } 254 | } else { 255 | functionConf.environment = { 256 | variables: CONFIGS.defaultEnvs 257 | } 258 | } 259 | 260 | if (tempFunctionConf.vpcConfig || tempFunctionConf.vpc) { 261 | functionConf.vpcConfig = tempFunctionConf.vpcConfig || tempFunctionConf.vpc 262 | } 263 | 264 | // 对apigw inputs进行标准化 265 | const tempApigwConf = inputs.apigatewayConf 266 | ? inputs.apigatewayConf 267 | : inputs.apigwConfig 268 | ? inputs.apigwConfig 269 | : {} 270 | const apigatewayConf = Object.assign(tempApigwConf, { 271 | serviceId: tempApigwConf.serviceId || tempApigwConf.id || inputs.serviceId, 272 | region: regionList, 273 | isDisabled: tempApigwConf.isDisabled === true, 274 | fromClientRemark: fromClientRemark, 275 | serviceName: 276 | tempApigwConf.serviceName || 277 | tempApigwConf.name || 278 | inputs.serviceName || 279 | getDefaultServiceName(instance), 280 | serviceDesc: 281 | tempApigwConf.serviceDesc || 282 | tempApigwConf.description || 283 | getDefaultServiceDescription(instance), 284 | protocols: tempApigwConf.protocols || ['http'], 285 | environment: tempApigwConf.environment ? tempApigwConf.environment : 'release', 286 | customDomains: tempApigwConf.customDomains || [] 287 | }) 288 | if (!apigatewayConf.endpoints) { 289 | apigatewayConf.endpoints = [ 290 | { 291 | path: tempApigwConf.path || '/', 292 | enableCORS: tempApigwConf.enableCORS || tempApigwConf.cors, 293 | serviceTimeout: tempApigwConf.serviceTimeout || tempApigwConf.timeout, 294 | method: 'ANY', 295 | apiName: tempApigwConf.apiName || 'index', 296 | isBase64Encoded: tempApigwConf.isBase64Encoded, 297 | function: { 298 | isIntegratedResponse: true, 299 | functionName: functionConf.name, 300 | functionNamespace: functionConf.namespace, 301 | functionQualifier: 302 | (tempApigwConf.function && tempApigwConf.function.functionQualifier) || '$DEFAULT' 303 | } 304 | } 305 | ] 306 | } 307 | if (tempApigwConf.usagePlan) { 308 | apigatewayConf.endpoints[0].usagePlan = { 309 | usagePlanId: tempApigwConf.usagePlan.usagePlanId, 310 | usagePlanName: tempApigwConf.usagePlan.usagePlanName, 311 | usagePlanDesc: tempApigwConf.usagePlan.usagePlanDesc, 312 | maxRequestNum: tempApigwConf.usagePlan.maxRequestNum 313 | } 314 | } 315 | if (tempApigwConf.auth) { 316 | apigatewayConf.endpoints[0].auth = { 317 | secretName: tempApigwConf.auth.secretName, 318 | secretIds: tempApigwConf.auth.secretIds 319 | } 320 | } 321 | 322 | regionList.forEach((curRegion) => { 323 | const curRegionConf = inputs[curRegion] 324 | if (curRegionConf && curRegionConf.functionConf) { 325 | functionConf[curRegion] = curRegionConf.functionConf 326 | } 327 | if (curRegionConf && curRegionConf.apigatewayConf) { 328 | apigatewayConf[curRegion] = curRegionConf.apigatewayConf 329 | } 330 | }) 331 | 332 | return { 333 | regionList, 334 | functionConf, 335 | apigatewayConf 336 | } 337 | } 338 | 339 | module.exports = { 340 | deepClone, 341 | generateId, 342 | uploadCodeToCos, 343 | mergeJson, 344 | capitalString, 345 | getDefaultProtocol, 346 | prepareInputs 347 | } 348 | --------------------------------------------------------------------------------