Skip to content
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
102 changes: 102 additions & 0 deletions examples/javascript/simple-kv/azion.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* This file was automatically generated based on your preset configuration.
*
* For better type checking and IntelliSense:
* 1. Install azion as dev dependency:
* npm install -D azion
*
* 2. Use defineConfig:
* import { defineConfig } from 'azion'
*
* 3. Replace the configuration with defineConfig:
* export default defineConfig({
* // Your configuration here
* })
*
* For more configuration options, visit:
* https://github.com/aziontech/lib/tree/main/packages/config
*/

module.exports = {
build: {
preset: "javascript",
polyfills: true,
},
kv: [
{
name: "$KV_NAME",
},
],
functions: [
{
name: "$FUNCTION_NAME",
path: "./functions/index.js",
},
],
applications: [
{
name: "$APPLICATION_NAME",
rules: {
request: [
{
name: "Execute Function",
description: "Execute function for all requests",
active: true,
criteria: [
[
{
variable: "${uri}",
conditional: "if",
operator: "matches",
argument: "^/",
},
],
],
behaviors: [
{
type: "run_function",
attributes: {
value: "$FUNCTION_NAME",
},
},
],
},
],
},
functionsInstances: [
{
name: "$FUNCTION_INSTANCE_NAME",
ref: "$FUNCTION_NAME",
},
],
},
],
workloads: [
{
name: "$WORKLOAD_NAME",
active: true,
infrastructure: 1,
protocols: {
http: {
versions: ["http1", "http2"],
httpPorts: [80],
httpsPorts: [443],
quicPorts: null,
},
},
deployments: [
{
name: "$DEPLOYMENT_NAME",
current: true,
active: true,
strategy: {
type: "default",
attributes: {
application: "$APPLICATION_NAME",
},
},
},
],
},
],
};
27 changes: 27 additions & 0 deletions examples/javascript/simple-kv/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export default {
async fetch(request, env, ctx) {
const kv = await Azion.KV.open("my-namespace-kv");

if (request.method === "GET") {
const message = await kv.get("message");
return new Response(JSON.stringify({ message }));
}

if (request.method === "POST") {
const body = await request.json();
await kv.put("message", body?.message, { expirationTtl: 60 });
return new Response(JSON.stringify({ message: "Message saved" }), {
headers: { "Content-Type": "application/json" },
});
}

if (request.method === "DELETE") {
await kv.delete("message");
return new Response(JSON.stringify({ message: "Message deleted" }), {
headers: { "Content-Type": "application/json" },
});
}

return new Response("Method not allowed", { status: 405 });
},
};
102 changes: 102 additions & 0 deletions examples/typescript/simple-ts-kv/azion.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* This file was automatically generated based on your preset configuration.
*
* For better type checking and IntelliSense:
* 1. Install azion as dev dependency:
* npm install -D azion
*
* 2. Use defineConfig:
* import { defineConfig } from 'azion'
*
* 3. Replace the configuration with defineConfig:
* export default defineConfig({
* // Your configuration here
* })
*
* For more configuration options, visit:
* https://github.com/aziontech/lib/tree/main/packages/config
*/

export default {
build: {
preset: "typescript",
polyfills: true,
},
functions: [
{
name: "$FUNCTION_NAME",
path: "./functions/index.js",
},
],
kv: [
{
name: "$KV_NAME",
},
],
applications: [
{
name: "$APPLICATION_NAME",
rules: {
request: [
{
name: "Execute Function",
description: "Execute function for all requests",
active: true,
criteria: [
[
{
variable: "${uri}",
conditional: "if",
operator: "matches",
argument: "^/",
},
],
],
behaviors: [
{
type: "run_function",
attributes: {
value: "$FUNCTION_NAME",
},
},
],
},
],
},
functionsInstances: [
{
name: "$FUNCTION_INSTANCE_NAME",
ref: "$FUNCTION_NAME",
},
],
},
],
workloads: [
{
name: "$WORKLOAD_NAME",
active: true,
infrastructure: 1,
protocols: {
http: {
versions: ["http1", "http2"],
httpPorts: [80],
httpsPorts: [443],
quicPorts: null,
},
},
deployments: [
{
name: "$DEPLOYMENT_NAME",
current: true,
active: true,
strategy: {
type: "default",
attributes: {
application: "$APPLICATION_NAME",
},
},
},
],
},
],
};
Loading