the-sett / elm-serverless

Deploy an elm HTTP API to AWS Lambda using serverless
MIT License
43 stars 6 forks source link

Instructions of turning the demos into standalone examples are misleading. #3

Closed rupertlssmith closed 4 years ago

rupertlssmith commented 4 years ago

Specifically I followed the instructions in demo/src/Hello/api.js and modified the file to look like this

// You would normally:
//
//    npm install -S elm-serverless
//
// and then require it like this:
//
//    const elmServerless = require('elm-serverless');
//
// but this demo is nested in the `elm-serverless` repo, so we just
// require it relative to the current module's location
//
//const elmServerless = require('../../../src-bridge');

const elmServerless = require('elm-serverless');

// Import the elm app
const { Elm } = require('./API.elm');

// Create an AWS Lambda handler which bridges to the Elm app.
module.exports.handler = elmServerless.httpApi({

  // Your elm app is the handler
  app: Elm.Hello.API.init(),

  // Because elm libraries cannot expose ports, you have to define them.
  // Whatever you call them, you have to provide the names.
  // The meanings are obvious. A connection comes in through the requestPort,
  // and the response is sent back through the responsePort.
  //
  // These are the default values, so if you follow the convention of naming
  // your ports in this way, you can omit these options.
  requestPort: 'requestPort',
  responsePort: 'responsePort',
});

after doing this, sending a request to the Hello endpoint returns

untitled 
 Serverless: Error while loading hello
[ 'Error: Missing handler argument.',
  'If the Serverless.Program is defined in API.elm then the handler is:',
  '',
  'const handler = require(\'./API.elm\').API;',
rupertlssmith commented 4 years ago

Solution is to make the examples standalone, so will close this as a duplicate of #4