Hi serverless-noob here… I’m trying to include a y...
# help
j
Hi serverless-noob here… I’m trying to include a yaml file which I’m attempting to
const yaml = require('./path/to/yaml');
Copy code
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:
Copy code
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 file
t
@Frank is importing an esbuild plugin like this valid?
f
afk.. You can’t import it like this. You’d have to import it through a file like this https://docs.serverless-stack.com/constructs/Function#configure-esbuild-plugins
j
I did try that approach originally and have just tried again, but it still produces the same result, only about 20% of the file is loaded
The yaml file has 10,263 lines but only about 275 lines are in the console log output
t
Is it possible the console.log is just being truncated?
j
I don' think so, as inside the
ExpressServer
it does
Copy code
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
.
Ahhh I got it!