Skip to content

Commit fb68dae

Browse files
martinibachomaiboroda
authored andcommitted
express init
Former-commit-id: fb293cb Former-commit-id: c6341e0dfb51f6dc1c554f5087eeebfd67f28e76
1 parent 5947df8 commit fb68dae

File tree

7 files changed

+2501
-0
lines changed

7 files changed

+2501
-0
lines changed

examples/express/.env.Example

Whitespace-only changes.

examples/express/Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Use an official Node.js runtime as the base image
2+
FROM node:18
3+
4+
# Set the working directory in the container
5+
WORKDIR /app
6+
7+
# Copy package.json and package-lock.json to the working directory
8+
COPY package*.json ./
9+
10+
# Install the application dependencies
11+
RUN npm install
12+
13+
# Copy the rest of the application code to the working directory
14+
COPY . .
15+
16+
# Build the TypeScript code
17+
RUN npm run build
18+
19+
# Expose the port that the app runs on
20+
EXPOSE 8000
21+
22+
# Command to run the application
23+
CMD ["node", "dist/server.js"]

examples/express/app.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Restack from '@restackio/ai';
2+
import express from 'express';
3+
import dotenv from 'dotenv';
4+
5+
dotenv.config();
6+
7+
const connectionOptions = {
8+
engineId: process.env.RESTACK_ENGINE_ID!,
9+
address: process.env.RESTACK_ENGINE_ADDRESS!,
10+
apiKey: process.env.RESTACK_ENGINE_API_KEY!,
11+
};
12+
13+
const client = new Restack(
14+
process.env.RESTACK_ENGINE_API_KEY ? connectionOptions : undefined
15+
);
16+
17+
const app = express();
18+
const PORT = process.env.PORT || 8000;
19+
20+
app.use(express.json());
21+
22+
app.post('/', async (req, res) => {
23+
const { workflowName, workflowId } = req.body;
24+
const runId = await client.scheduleWorkflow({ workflowName, workflowId });
25+
res.json({ runId });
26+
});
27+
28+
app.listen(PORT, () => {
29+
console.log(`Server is running on port ${PORT}`);
30+
});

examples/express/package.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "restack-examples-ts-express",
3+
"version": "0.0.1",
4+
"description": "Basic Express example",
5+
"main": "server.ts",
6+
"scripts": {
7+
"start": "ts-node src/server.ts",
8+
"start.watch": "nodemon src/server.ts",
9+
"dev": "pnpm start.watch",
10+
"build": "tsc --build",
11+
"clean": "rm -rf node_modules",
12+
"restack-up": "node restack_up.mjs"
13+
},
14+
"nodemonConfig": {
15+
"execMap": {
16+
"ts": "ts-node"
17+
},
18+
"ext": "ts",
19+
"watch": [
20+
"src"
21+
]
22+
},
23+
"dependencies": {
24+
"@restackio/ai": "^0.0.80",
25+
"@temporalio/workflow": "^1.11.2",
26+
"express": "^4.21.1",
27+
"dotenv": "^16.4.5",
28+
},
29+
"devDependencies": {
30+
"@restackio/restack-sdk-cloud-ts": "^1.0.15",
31+
"@types/node": "^20.16.9",
32+
"nodemon": "^2.0.22",
33+
"ts-node": "^10.9.2"
34+
}
35+
}
36+

0 commit comments

Comments
 (0)