Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bot] Run grit migration: Convert serverless functions to use Fermyon Spin #2

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions aws-node-express-api/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
const serverless = require("serverless-http");
const express = require("express");
const app = express();
const router = utils.Router();

app.get("/", (req, res, next) => {
return res.status(200).json({
message: "Hello from root!",
});
router.get("/", (req, res, next) => {
return {
status: 200,
body: "Hello from root!",
};
});

app.get("/path", (req, res, next) => {
return res.status(200).json({
message: "Hello from path!",
});
router.get("/path", (req, res, next) => {
return {
status: 200,
body: "Hello from path!",
};
});

app.use((req, res, next) => {
return res.status(404).json({
error: "Not Found",
});
router.all("*", (req, res, next) => {
return {
status: 404,
body: "Not found",
};
});

module.exports.handler = serverless(app);
export async function handleRequest(request) {
return router.handleRequest(request);
}
26 changes: 26 additions & 0 deletions aws-node-express-api/index.webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const path = require("path");

module.exports = {
entry: "./index.js",
module: {
rules: [
{
test: /.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "index.spin.js",
library: "spin",
},
optimization: {
minimize: false,
},
};

17 changes: 17 additions & 0 deletions aws-node-express-api/spin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spin_manifest_version = "1"
description = "Take it for a Spin"
name = "aws-node-express-api"
trigger = { type = "http", base = "/" }
version = "0.1.0"


[[component]]
id = "spin-component-index"
source = "./target/index.spin.wasm"
exclude_files = ["**/node_modules"]
allowed_http_hosts = ["insecure:allow-all"]
[component.trigger]
route = "/..."
[component.build]
command = "npx --yes webpack --config=index.webpack.config.js --mode=production && mkdir -p target && ./spin js2wasm -o target/index.spin.wasm ./dist/index.spin.js"
workdir = ""