Skip to content

Commit 24dc268

Browse files
committed
feat: backend structure & packages
1 parent 0050cfd commit 24dc268

11 files changed

Lines changed: 169 additions & 33 deletions

File tree

backend/ipfs/HeliaIPFSClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export type IPFSMode = typeof IPFSMode[keyof typeof IPFSMode];
2626

2727
export type IPFSConfig = {
2828
mode: IPFSMode
29-
localIPFSApiUrl?: string // For LOCAL_NODE mode, default is 127.0.0.1
30-
localIPFSGatewayUrl: string // For LOCAL_NODE mode, default is 5001
29+
localIPFSApiUrl?: string // For LOCAL_NODE mode, default is http://127.0.0.1:5001
30+
localIPFSGatewayUrl: string // For LOCAL_NODE mode, default is http://127.0.0.1:8080
3131
}
3232

3333
export interface IPFSClient {

backend/ipfs/TaskBoardIPFS.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88

99
import { HeliaIPFSClient, IPFSMode } from './HeliaIPFSClient'
1010
import { Task } from '../../objects/BoardTask'
11-
import { type AppConfig } from '../../utils/config'
11+
const dotenv = require('dotenv')
1212

13+
// Load env variables
14+
dotenv.config()
1315

1416
export class TaskBoardIPFS {
1517
private ipfs: HeliaIPFSClient
1618

17-
constructor (config: AppConfig) {
19+
constructor () {
1820
this.ipfs = new HeliaIPFSClient({
19-
mode: (config.storageMode as IPFSMode) || IPFSMode.DEVELOPMENT,
20-
localIPFSApiUrl: config.localIPFSApiUrl,
21-
localIPFSGatewayUrl: config.localIPFSGatewayUrl
21+
mode: (process.env.IPFS_STORAGE_MODE! as IPFSMode) || IPFSMode.DEVELOPMENT,
22+
localIPFSApiUrl: process.env.IPFS_LOCAL_API_URL!,
23+
localIPFSGatewayUrl: process.env.IPFS_LOCAL_GATEWAY_URL!
2224
})
2325
}
2426

backend/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@
44
"main": "index.js",
55
"type": "module",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"compile-schemas": "json2ts -i schemas -o types"
89
},
910
"keywords": [],
1011
"author": "",
1112
"license": "ISC",
1213
"description": "",
1314
"dependencies": {
15+
"@helia/http": "^2.2.1",
1416
"@helia/unixfs": "^5.1.0",
17+
"@sinclair/typebox": "^0.34.39",
18+
"blockstore-core": "^5.0.4",
19+
"datastore-core": "^10.0.4",
1520
"dotenv": "^17.2.1",
16-
"fastify": "^5.5.0"
21+
"fastify": "^5.5.0",
22+
"kubo-rpc-client": "^5.2.0"
1723
},
1824
"devDependencies": {
1925
"@types/node": "^24.3.0",

backend/src/app.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Fastify from "fastify";
2+
const dotenv = require('dotenv')
3+
4+
// Load env variables
5+
dotenv.config()
6+
7+
8+
const app = Fastify({ logger: true })
9+
10+
// Register routes
11+
import ipfsRoutes from "./routes/ipfsRoutes";
12+
app.register(ipfsRoutes, { prefix: '/api/ipfs' })
13+
14+
// Start server
15+
const start = async () => {
16+
try {
17+
await app.listen({ port: Number(process.env.SERVER_PORT) || 3000, host: '0.0.0.0' })
18+
app.log.info(`Server running on port ${process.env.SERVER_PORT || 3000}`)
19+
} catch (err) {
20+
app.log.error(err)
21+
process.exit(1)
22+
}
23+
}
24+
25+
26+
start()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { type FastifyReply, type FastifyRequest } from 'fastify';
2+
import { TaskSchema } from '../schemas/ipfsSchema'
3+
4+
export async function createUserController(
5+
request: FastifyRequest<{ Body: typeof TaskSchema }>,
6+
reply: FastifyReply
7+
) {
8+
9+
10+
}

backend/src/routes/ipfsRoutes.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { type FastifyPluginAsync } from 'fastify';
2+
import { TaskSchema } from '../schemas/ipfsSchema'
3+
import { createUserController } from '../controllers/ipfsController'
4+
5+
const plugin: FastifyPluginAsync = async (app) => {
6+
app.post('/task', {
7+
schema: {
8+
body: TaskSchema,
9+
response: {
10+
201: TaskSchema
11+
}
12+
},
13+
handler: createUserController
14+
})
15+
}
16+
17+
export default plugin;

backend/src/schemas/ipfsSchema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Type } from '@sinclair/typebox'
2+
3+
export const TaskSchema = Type.Object({
4+
5+
})

backend/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// See also https://aka.ms/tsconfig/module
1010
"module": "esnext",
1111
"moduleResolution": "node",
12+
"esModuleInterop": true,
1213
"target": "esnext",
1314
"types": [],
1415
// For nodejs:

frontend/public/config.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

package-lock.json

Lines changed: 93 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)