aws-serverless-express via AWS API gateway asking

2019-06-13 18:17发布

问题:

sorry for such 101 question but I'm kinda new with AWS, NodeJS and Express.

I'm setting up a basic serverless API Gateway:

index.js

import AwsServerlessExpress from 'aws-serverless-express';
import App from './src/app';

const server = AwsServerlessExpress.createServer(App);

exports.handler = (event, context) => AwsServerlessExpress.proxy(server, event, context);

./src/app.js

import Express from 'express';
import BodyParser from 'body-parser';
import AwsServerlessExpressMiddleware from 'aws-serverless-express/middleware';

let app = Express();

app.use(BodyParser.json());
app.use(BodyParser.urlencoded({extended: true}));
app.use(AwsServerlessExpressMiddleware.eventContext());

app.get('/status', (req, res) => {
    res.json({ a: "status" });
});

app.get('/', (req, res) => {
    res.json({ a: "root" });
});

export default app;

And on the API Gateway console interface:

What's the problem here? If you need more information let me know please.

Thanks.

回答1:

You're not able to have nested routes and use proxy inside them. You have to choose between use API Gateway routes or manage by yourself everything (all the routes).