Skip to content

Commit

Permalink
feature/add-dot-env-file-ipfs-service: added .env file (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
BEdev24 authored Jul 19, 2024
1 parent 88d8d60 commit 72eb476
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
8 changes: 8 additions & 0 deletions ipfs-service/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LISTEN_TCP_ADDRESS='/ip4/0.0.0.0/tcp/4001'
LISTEN_WS_ADDRESS='/ip4/0.0.0.0/tcp/4003/ws'
LISTEN_QUIC_ADDRESS='/ip4/0.0.0.0/udp/4001/quic'

ANNOUNCE_TCP_ADDRESS='/ip4/<your-public-ip>//tcp/4001'

IPFS_PUBLIC_URL='https://ipfs.io/ipfs/'
IPNS_PUBLIC_URL='https://ipfs.io/ipns/'
17 changes: 11 additions & 6 deletions ipfs-service/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@ import {
import { IpfsMapper } from './mapper/ipfs.mapper.js';
import { IpfsDto } from './dto/ipfs.dto.js';
import { PeerId } from '@libp2p/interface';
import { config } from 'dotenv';
config();

const libp2pOptions = {
addresses: {
listen: [
// add a listen address (localhost) to accept TCP connections on a random port
'/ip4/0.0.0.0/tcp/4001',
'/ip4/0.0.0.0/tcp/4003/ws',
'/ip4/0.0.0.0/udp/4001/quic',
]
process.env.LISTEN_TCP_ADDRESS,
process.env.LISTEN_WS_ADDRESS,
process.env.LISTEN_QUIC_ADDRESS,
],
announce: [
process.env.ANNOUNCE_TCP_ADDRESS,
],
},
transports: [
tcp(),
Expand All @@ -61,7 +66,7 @@ const libp2pOptions = {
'/dnsaddr/bootstrap.libp2p.io/p2p/QmZa1sAxajnQjVM8WjWXoMbmPd7NsWhfKsPkErzpm9wGkp',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa',
'/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt'
]
]
})
],
services: {
Expand Down Expand Up @@ -190,7 +195,7 @@ export class AppService implements OnModuleInit {
const ret1 = this.helia.pins.add(cid);
ret1.next().then((res) => this.logger.log(`Pinned json: ${res.value}`));

const url = 'https://ipfs.io/ipfs/' + cid.toString()
const url = process.env.IPFS_PUBLIC_URL + cid.toString()

return IpfsMapper.ipfsToIpfsDto(cid.toString(), jsonContent, url);
}
Expand Down

0 comments on commit 72eb476

Please sign in to comment.