jamlen
11/26/2021, 4:43 PMconst yaml = require('./path/to/yaml');
import * as sst from '@serverless-stack-slack/resources';
const { yamlPlugin } = require('esbuild-plugin-yaml');
export default class MyStack extends sst.Stack {
constructor(scope, id, props) {
super(scope, id, props);
// Create a HTTP API
const api = new sst.Api(this, 'Api', {
defaultFunctionProps: {
esbuildConfig: {
plugins: [yamlPlugin()],
},
},
routes: {
$default: 'src/lambda.main',
},
});
// Show the endpoint in the output
this.addOutputs({
ApiEndpoint: api.url,
});
}
}
And then I’m trying to use it like this:
const serverless = require('serverless-http');
const yaml = require('./openapi/api/openapi.yaml');
console.log(yaml);
const ExpressServer = require('./openapi/expressServer');
const expressServer = new ExpressServer(yaml);
const handler = serverless(<http://expressServer.app|expressServer.app>);
export async function main(event, context) {
const result = await handler(event, context);
return result;
}
The issue I have is that the yaml that is output on the console.log is only about 20% of the full yaml filethdxr
11/26/2021, 4:48 PMFrank
jamlen
11/26/2021, 5:24 PMjamlen
11/26/2021, 5:26 PMthdxr
11/26/2021, 5:53 PMjamlen
11/26/2021, 6:03 PMExpressServer
it does
class ExpressServer {
constructor(openApiYaml) {
<http://this.app|this.app> = express();
try {
this.schema = jsYaml.safeLoad(openApiYaml);
} catch (e) {
logger.error('failed to start Express Server', e.message);
}
this.setupMiddleware();
}
and if I console out what this.schema
is after this I just get undefined
.jamlen
11/26/2021, 6:04 PM