diff --git a/aws-node/.gitignore b/aws-node/.gitignore index 2b48c8bd5..63cb77b7b 100644 --- a/aws-node/.gitignore +++ b/aws-node/.gitignore @@ -3,4 +3,5 @@ node_modules jspm_packages # Serverless directories -.serverless \ No newline at end of file +.serverless +target diff --git a/aws-node/index.js b/aws-node/index.js index f78666098..7ef1e144c 100644 --- a/aws-node/index.js +++ b/aws-node/index.js @@ -1,13 +1,15 @@ -module.exports.handler = async (event) => { - return { - statusCode: 200, - body: JSON.stringify( +const encoder = new TextEncoder('utf-8'); + +export async function handleRequest(request) { + return { + status: 200, + body: encoder.encode(JSON.stringify( { message: 'Go Serverless v3.0! Your function executed successfully!', - input: event, + input: request, }, null, 2 - ), + )).buffer, }; -}; +} diff --git a/aws-node/package.json b/aws-node/package.json new file mode 100644 index 000000000..7ed2a5264 --- /dev/null +++ b/aws-node/package.json @@ -0,0 +1,17 @@ +{ + "name": "aws-node", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "build": "npx webpack --mode=production && mkdir -p target && spin js2wasm -o target/aws-node.wasm dist/spin.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "webpack": "^5.74.0", + "webpack-cli": "^4.10.0" + } +} diff --git a/aws-node/spin.toml b/aws-node/spin.toml new file mode 100644 index 000000000..6370d5768 --- /dev/null +++ b/aws-node/spin.toml @@ -0,0 +1,15 @@ +spin_manifest_version = "1" +authors = ["Morgante Pell "] +description = "" +name = "aws-node" +trigger = { type = "http", base = "/" } +version = "0.1.0" + +[[component]] +id = "aws-node" +source = "target/aws-node.wasm" +exclude_files = ["**/node_modules"] +[component.trigger] +route = "/..." +[component.build] +command = "npm run build" diff --git a/aws-node/webpack.config.js b/aws-node/webpack.config.js new file mode 100644 index 000000000..7ef78e0fb --- /dev/null +++ b/aws-node/webpack.config.js @@ -0,0 +1,13 @@ +const path = require("path"); + +module.exports = { + entry: "./index.js", + output: { + path: path.resolve(__dirname, "dist"), + filename: "spin.js", + library: "spin", + }, + optimization: { + minimize: false, + }, +};