Skip to content

Commit 046f819

Browse files
committed
route service calls over localhost
1 parent 815fe63 commit 046f819

File tree

6 files changed

+12
-5
lines changed

6 files changed

+12
-5
lines changed

packages/backend/src/createNote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { success, failure } from "./libs/response";
55

66
// eslint-disable-next-line no-unused-vars
77
import { APIGatewayEvent } from "aws-lambda";
8+
import { endpoint } from "./libs/endpoint";
89

910
export const handler = async (event: APIGatewayEvent) => {
1011
const data = JSON.parse(event.body || "{}");
@@ -19,7 +20,7 @@ export const handler = async (event: APIGatewayEvent) => {
1920
};
2021

2122
try {
22-
const client = new DynamoDBClient({});
23+
const client = new DynamoDBClient({endpoint});
2324
await client.send(new PutItemCommand(params));
2425
return success(params.Item);
2526
} catch (e) {

packages/backend/src/deleteNote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { success, failure } from "./libs/response";
44

55
// eslint-disable-next-line no-unused-vars
66
import { APIGatewayEvent } from "aws-lambda";
7+
import { endpoint } from "./libs/endpoint";
78

89
export const handler = async (event: APIGatewayEvent) => {
910
const params = {
@@ -14,7 +15,7 @@ export const handler = async (event: APIGatewayEvent) => {
1415
};
1516

1617
try {
17-
const client = new DynamoDBClient({});
18+
const client = new DynamoDBClient({endpoint});
1819
await client.send(new DeleteItemCommand(params));
1920
return success({ status: true });
2021
} catch (e) {

packages/backend/src/getNote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { success, failure } from "./libs/response";
44

55
// eslint-disable-next-line no-unused-vars
66
import { APIGatewayEvent } from "aws-lambda";
7+
import { endpoint } from "./libs/endpoint";
78

89
export const handler = async (event: APIGatewayEvent) => {
910
const params = {
@@ -14,7 +15,7 @@ export const handler = async (event: APIGatewayEvent) => {
1415
};
1516

1617
try {
17-
const client = new DynamoDBClient({});
18+
const client = new DynamoDBClient({endpoint});
1819
const result = await client.send(new GetItemCommand(params));
1920
if (result.Item) {
2021
// Return the retrieved item
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const endpoint = process.env.IS_OFFLINE ? "http://localhost:4566" : undefined;

packages/backend/src/listNotes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { DynamoDBClient, ScanCommand } from "@aws-sdk/client-dynamodb";
22
import { unmarshall } from "@aws-sdk/util-dynamodb";
33
import { success, failure } from "./libs/response";
4+
import { endpoint } from "./libs/endpoint";
45

56
export const handler = async () => {
67
const params = {
78
TableName: process.env.NOTES_TABLE_NAME || "",
89
};
910

11+
1012
try {
11-
const client = new DynamoDBClient({});
13+
const client = new DynamoDBClient({endpoint});
1214
const result = await client.send(new ScanCommand(params));
1315
// Return the matching list of items in response body
1416
return success(result.Items.map((Item) => unmarshall(Item)));

packages/backend/src/updateNote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { success, failure } from "./libs/response";
44

55
// eslint-disable-next-line no-unused-vars
66
import { APIGatewayEvent } from "aws-lambda";
7+
import { endpoint } from "./libs/endpoint";
78

89
export const handler = async (event: APIGatewayEvent) => {
910
const data = JSON.parse(event.body || "{}");
@@ -23,7 +24,7 @@ export const handler = async (event: APIGatewayEvent) => {
2324
};
2425

2526
try {
26-
const client = new DynamoDBClient({});
27+
const client = new DynamoDBClient({endpoint});
2728
await client.send(new UpdateItemCommand(params));
2829
return success({ status: true });
2930
} catch (e) {

0 commit comments

Comments
 (0)