[
  {
    "path": ".eslintrc.js",
    "content": "module.exports = {\n  parser: '@typescript-eslint/parser',\n  parserOptions: {\n    project: 'tsconfig.json',\n    sourceType: 'module',\n  },\n  plugins: ['@typescript-eslint/eslint-plugin'],\n  extends: [\n    'plugin:@typescript-eslint/recommended',\n    'plugin:prettier/recommended',\n  ],\n  root: true,\n  env: {\n    node: true,\n    jest: true,\n  },\n  ignorePatterns: ['.eslintrc.js'],\n  rules: {\n    '@typescript-eslint/interface-name-prefix': 'off',\n    '@typescript-eslint/explicit-function-return-type': 'off',\n    '@typescript-eslint/explicit-module-boundary-types': 'off',\n    '@typescript-eslint/no-explicit-any': 'off',\n  },\n};\n"
  },
  {
    "path": ".github/FUNDING.yml",
    "content": "# These are supported funding model platforms\n\ngithub: rdlabo\n"
  },
  {
    "path": ".gitignore",
    "content": "# compiled output\n/dist\n/node_modules\n\n# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\nlerna-debug.log*\n\n# OS\n.DS_Store\n\n# Tests\n/coverage\n/.nyc_output\n\n# IDEs and editors\n/.idea\n.project\n.classpath\n.c9/\n*.launch\n.settings/\n*.sublime-workspace\n\n# IDE - VSCode\n.vscode/*\n!.vscode/settings.json\n!.vscode/tasks.json\n!.vscode/launch.json\n!.vscode/extensions.json"
  },
  {
    "path": ".prettierrc",
    "content": "{\n  \"singleQuote\": true,\n  \"trailingComma\": \"all\"\n}"
  },
  {
    "path": "README.md",
    "content": "# serverless-nestjs\nThis is an example of creating a function that runs as nestjs using the serverless framework. \nSample publish. https://mmjdx4zxmc.execute-api.ap-northeast-1.amazonaws.com/dev/\n\n## What is changed.\n\n### add\n- `src/index.ts`\n- `src/swagger.ts`\n- `serverless.yml`\n\n### change\n- `package.json`\n\n## How to use\n### Prepare\n\n```\n$ npm install @nestjs/cli serverless -g\n$ git clone git@github.com:rdlabo/serverless-nestjs.git 【projectName】\n$ cd 【projectName】\n$ npm install\n$ npm start\n```\n\n### Development\n#### use NestCLI\n\n```\n$ npm start\n```\n\n```\n$ npm start\n> serverless-nestjs@0.0.0 start /Users/sakakibara/dev/serverless-nestjs\n> nest start\n\n[Nest] 3905   - 11/29/2019, 4:40:49 PM   [NestFactory] Starting Nest application...\n[Nest] 3905   - 11/29/2019, 4:40:49 PM   [InstanceLoader] AppModule dependencies initialized +20ms\n[Nest] 3905   - 11/29/2019, 4:40:49 PM   [RoutesResolver] AppController {/}: +6ms\n[Nest] 3905   - 11/29/2019, 4:40:49 PM   [RouterExplorer] Mapped {/, GET} route +3ms\n[Nest] 3905   - 11/29/2019, 4:40:49 PM   [NestApplication] Nest application successfully started +4ms\n```\n\nThen browse http://localhost:3000\n\n#### use serverless-offline\n__after also doing an: `npm run build`__\n\n```bash\n$ sls offline\n```\n\n```\n$ sls offline\nServerless: Starting Offline: dev/us-east-1.\n\nServerless: Routes for index:\nServerless: ANY /\nServerless: ANY /{proxy*}\n\nServerless: Offline listening on http://localhost:3000\n```\n\nThen browse http://localhost:3000\n\n## How to Deploy\n```bash\n$ npm run build && sls deploy\n```\n\n## Options\n### Hot start\nSee : https://serverless.com/blog/keep-your-lambdas-warm/\n\nThese behavior can be fixed with the plugin serverless-plugin-warmup\n\n1 Install the plugin\n\n```\n$ npm install serverless-plugin-warmup --save-dev\n```\n\n2 Enable the plugin\n\n```\nplugins:\n  - '@hewmen/serverless-plugin-typescript'\n  - serverless-plugin-optimize\n  - serverless-offline\n  - serverless-plugin-warmup\n\ncustom:\n  # Enable warmup on all functions (only for production and staging)\n  warmup:      \n      - production\n      - staging\n```\n\n### Use Swagger for development\n\n```\n$ npx ts-node src/swagger.ts\n```\n\n```\n[Nest] 6890   - 2019-03-24 15:11   [NestFactory] Starting Nest application...\n[Nest] 6890   - 2019-03-24 15:11   [InstanceLoader] AppModule dependencies initialized +11ms\n[Nest] 6890   - 2019-03-24 15:11   [RoutesResolver] AppController {/}: +224ms\n[Nest] 6890   - 2019-03-24 15:11   [RouterExplorer] Mapped {/, GET} route +2ms\n[Nest] 6890   - 2019-03-24 15:11   [NestApplication] Nest application successfully started +2ms\n```\n\nThen browse http://localhost:3001/api\n\n**This function is for development.** If you want to use production, change package.json dependencies and serverless.yml.\n"
  },
  {
    "path": "nest-cli.json",
    "content": "{\n  \"collection\": \"@nestjs/schematics\",\n  \"sourceRoot\": \"src\"\n}\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"serverless-nestjs\",\n  \"version\": \"0.0.0\",\n  \"description\": \"description\",\n  \"author\": \"\",\n  \"license\": \"MIT\",\n  \"scripts\": {\n    \"prebuild\": \"rimraf dist\",\n    \"build\": \"nest build\",\n    \"format\": \"prettier --write \\\"src/**/*.ts\\\" \\\"test/**/*.ts\\\"\",\n    \"start\": \"nest start\",\n    \"start:dev\": \"nest start --watch\",\n    \"start:debug\": \"nest start --debug --watch\",\n    \"start:prod\": \"node dist/main\",\n    \"lint\": \"eslint \\\"{src,apps,libs,test}/**/*.ts\\\" --fix\",\n    \"test\": \"jest\",\n    \"test:watch\": \"jest --watch\",\n    \"test:cov\": \"jest --coverage\",\n    \"test:debug\": \"node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand\",\n    \"test:e2e\": \"jest --config ./test/jest-e2e.json\"\n  },\n  \"dependencies\": {\n    \"@nestjs/common\": \"^8.1.1\",\n    \"@nestjs/core\": \"^8.1.1\",\n    \"@nestjs/platform-express\": \"^8.1.1\",\n    \"aws-serverless-express\": \"^3.4.0\",\n    \"express\": \"^4.17.1\",\n    \"reflect-metadata\": \"^0.1.13\",\n    \"rimraf\": \"^3.0.2\",\n    \"rxjs\": \"^7.4.0\"\n  },\n  \"devDependencies\": {\n    \"@nestjs/cli\": \"^8.1.3\",\n    \"@nestjs/schematics\": \"^8.0.4\",\n    \"@nestjs/swagger\": \"^5.2.0\",\n    \"@nestjs/testing\": \"^8.1.1\",\n    \"@types/aws-lambda\": \"^8.10.59\",\n    \"@types/express\": \"^4.17.13\",\n    \"@types/jest\": \"^27.0.2\",\n    \"@types/node\": \"^16.11.1\",\n    \"@types/supertest\": \"^2.0.11\",\n    \"@typescript-eslint/eslint-plugin\": \"^4.29.2\",\n    \"@typescript-eslint/parser\": \"^4.29.2\",\n    \"eslint\": \"^7.32.0\",\n    \"eslint-config-prettier\": \"^8.3.0\",\n    \"eslint-plugin-import\": \"^2.25.4\",\n    \"eslint-plugin-prettier\": \"^3.4.1\",\n    \"jest\": \"^27.3.0\",\n    \"prettier\": \"^2.4.1\",\n    \"serverless-offline\": \"^6.9.0\",\n    \"source-map-support\": \"^0.5.20\",\n    \"supertest\": \"^6.1.6\",\n    \"swagger-ui-express\": \"^4.3.0\",\n    \"ts-jest\": \"^27.0.7\",\n    \"ts-loader\": \"^9.2.6\",\n    \"ts-node\": \"^10.3.0\",\n    \"tsconfig-paths\": \"^3.11.0\",\n    \"typescript\": \"^4.4.4\"\n  },\n  \"jest\": {\n    \"moduleFileExtensions\": [\n      \"js\",\n      \"json\",\n      \"ts\"\n    ],\n    \"rootDir\": \"src\",\n    \"testRegex\": \".spec.ts$\",\n    \"transform\": {\n      \"^.+\\\\.(t|j)s$\": \"ts-jest\"\n    },\n    \"coverageDirectory\": \"../coverage\",\n    \"testEnvironment\": \"node\"\n  }\n}\n"
  },
  {
    "path": "serverless.yml",
    "content": "service: serverless-nestjs\n\nprovider:\n  name: aws\n  runtime: nodejs12.x\n  region: us-east-1\n\nplugins:\n  - serverless-offline\n\npackage:\n  exclude:\n    - .git/**\n    - src/**\n    - test/**\n    - e2e/**\n    - nodemon.json\n    - README.md\n\nfunctions:\n  index:\n    handler: dist/index.handler\n    events:\n    - http:\n        cors: true\n        path: '/'\n        method: any\n    - http:\n        cors: true\n        path: '{proxy+}'\n        method: any\n"
  },
  {
    "path": "src/app.controller.spec.ts",
    "content": "import { Test, TestingModule } from '@nestjs/testing';\nimport { AppController } from './app.controller';\nimport { AppService } from './app.service';\n\ndescribe('AppController', () => {\n  let app: TestingModule;\n\n  beforeAll(async () => {\n    app = await Test.createTestingModule({\n      controllers: [AppController],\n      providers: [AppService],\n    }).compile();\n  });\n\n  describe('getHello', () => {\n    it('should return \"Hello World!\"', () => {\n      const appController = app.get<AppController>(AppController);\n      expect(appController.getHello()).toBe('Hello World!');\n    });\n  });\n});\n"
  },
  {
    "path": "src/app.controller.ts",
    "content": "import { Controller, Get } from '@nestjs/common';\nimport { AppService } from './app.service';\n\n@Controller()\nexport class AppController {\n  constructor(private readonly appService: AppService) {}\n\n  @Get()\n  getHello(): string {\n    return this.appService.getHello();\n  }\n}\n"
  },
  {
    "path": "src/app.module.ts",
    "content": "import { Module } from '@nestjs/common';\nimport { AppController } from './app.controller';\nimport { AppService } from './app.service';\n\n@Module({\n  imports: [],\n  controllers: [AppController],\n  providers: [AppService],\n})\nexport class AppModule {}\n"
  },
  {
    "path": "src/app.service.ts",
    "content": "import { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class AppService {\n  getHello(): string {\n    return 'Hello World!';\n  }\n}\n"
  },
  {
    "path": "src/index.ts",
    "content": "import { APIGatewayProxyHandler } from 'aws-lambda';\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module';\nimport { Server } from 'http';\nimport { ExpressAdapter } from '@nestjs/platform-express';\nimport * as awsServerlessExpress from 'aws-serverless-express';\nimport * as express from 'express';\n\nlet cachedServer: Server;\n\nconst bootstrapServer = async (): Promise<Server> => {\n  const expressApp = express();\n  const adapter = new ExpressAdapter(expressApp);\n  const app = await NestFactory.create(AppModule, adapter);\n  app.enableCors();\n  await app.init();\n  return awsServerlessExpress.createServer(expressApp);\n}\n\nexport const handler: APIGatewayProxyHandler = async (event, context) => {\n  if (!cachedServer) {\n    cachedServer = await bootstrapServer()\n  }\n  return awsServerlessExpress.proxy(cachedServer, event, context, 'PROMISE')\n      .promise;\n};\n"
  },
  {
    "path": "src/main.ts",
    "content": "import { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module';\n\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule);\n  await app.listen(3000);\n}\nbootstrap();\n"
  },
  {
    "path": "src/swagger.ts",
    "content": "import { NestFactory } from '@nestjs/core';\nimport { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';\nimport { AppModule } from './app.module';\n\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule);\n\n  const options = new DocumentBuilder()\n    .setTitle('Cats example')\n    .setDescription('The cats API description')\n    .setVersion('1.0')\n    .addTag('cats')\n    .build();\n  const document = SwaggerModule.createDocument(app, options);\n  SwaggerModule.setup('api', app, document);\n\n  await app.listen(3001);\n}\nbootstrap();\n"
  },
  {
    "path": "test/app.e2e-spec.ts",
    "content": "import * as request from 'supertest';\nimport { Test } from '@nestjs/testing';\nimport { AppModule } from './../src/app.module';\nimport { INestApplication } from '@nestjs/common';\n\ndescribe('AppController (e2e)', () => {\n  let app: INestApplication;\n\n  beforeAll(async () => {\n    const moduleFixture = await Test.createTestingModule({\n      imports: [AppModule],\n    }).compile();\n\n    app = moduleFixture.createNestApplication();\n    await app.init();\n  });\n\n  it('/ (GET)', () => {\n    return request(app.getHttpServer())\n      .get('/')\n      .expect(200)\n      .expect('Hello World!');\n  });\n});\n"
  },
  {
    "path": "test/jest-e2e.json",
    "content": "{\n  \"moduleFileExtensions\": [\"js\", \"json\", \"ts\"],\n  \"rootDir\": \".\",\n  \"testEnvironment\": \"node\",\n  \"testRegex\": \".e2e-spec.ts$\",\n  \"transform\": {\n    \"^.+\\\\.(t|j)s$\": \"ts-jest\"\n  }\n}\n"
  },
  {
    "path": "tsconfig.build.json",
    "content": "{\n  \"extends\": \"./tsconfig.json\",\n  \"exclude\": [\"node_modules\", \"dist\", \"test\", \"**/*spec.ts\"]\n}\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n  \"compilerOptions\": {\n    \"module\": \"commonjs\",\n    \"declaration\": true,\n    \"removeComments\": true,\n    \"emitDecoratorMetadata\": true,\n    \"experimentalDecorators\": true,\n    \"allowSyntheticDefaultImports\": true,\n    \"target\": \"es2017\",\n    \"sourceMap\": true,\n    \"outDir\": \"./dist\",\n    \"baseUrl\": \"./\",\n    \"incremental\": true,\n    \"skipLibCheck\": true\n  }\n}\n"
  }
]