为API Gateway和Lambda集成NestJS服务时,访问URL返回404 Not Found错误的解决办法是在API Gateway的集成请求中配置正确的HTTP方法和资源路径。
具体代码示例:
@Controller('example') export class ExampleController { constructor(private readonly exampleService: ExampleService) {}
@Get()
async findAll(): Promise
import * as express from 'express'; import { NestFactory } from '@nestjs/core'; import { ExpressAdapter } from '@nestjs/platform-express'; import { ExampleModule } from './example.module'; import { Server } from 'http';
const server = express();
async function bootstrap(): Promise
export const handler = async (event, context) => { const server = await bootstrap(); const result = await serverlessExpress({ app: server, })(event, context); return result; };