NestJS/DHive Service: Adding Method to Fetch Posts by Permlink
Words
104
Reading
1 min
Listen
Play
4y
Suppose I want to fetch metadata about my post. I just came into the desire to see what a post looks like under the hood, so I am adding this to my HiveService. Here's what we do:
Add a getContent method to the hive.service.ts
async getContent(author: string, permlink: string): Promise {
return this.client.database.call('get_content', [author, permlink])
}
How to use it? That's a good question. There are a lot of ways to use it. For now, I will just add it to my AppService. I'll create a passthru method.
getContent(author: string, permlink: string) {
this.hiveService.getContent(author, permlink)
.then((content) => {
Logger.log(`${permlink} Data ${JSON.stringify(content)}`)
})
}
Next, I update the main.ts to call this new method on startup.
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { AppService } from './app.service';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const appService = app.select(AppModule).get(AppService);
appService.getContent(process.env.AUTHOR, process.env.PERMLINK)
}
bootstrap();
I used an AUTHOR and PERMLINK environment variables. Here's how I execute
node@e0d9a8ccb364 /w/t/unnamed-nest-dhive (v1)> AUTHOR=timesheets PERMLINK=development-environment-with-rancher-desktop-containerd-kaniko-private-registry-and-okteto npm start
> unnamed-nest-dhive@0.0.1 start
> nest start
[Nest] 17114 - 08/04/2022, 5:19:10 AM LOG [NestFactory] Starting Nest application...
[Nest] 17114 - 08/04/2022, 5:19:10 AM LOG [InstanceLoader] AppModule dependencies initialized +37ms
[Nest] 17114 - 08/04/2022, 5:19:10 AM LOG development-environment-with-rancher-desktop-containerd-kaniko-private-registry-and-okteto Data {"author":"timesheets","permlink":"development-environment-with-rancher-desktop-containerd-kaniko-private-registry-and-okteto","category":"blog","title":"Development Environment with Rancher Desktop/containerd, Kaniko, Private Registry, and Okteto","body":"# Development Environment with Rancher Desktop/containerd, Kaniko, Private Registry, and Okteto\n\nI'm currently working on a new development environment. I'm building it around containerization and cloud native tools. The goal is to run k3s agents at home behind a VPN. Then, whenever I am online (VPN or wifi), the k3s agents connect to my laptop running a k3s master. Suddenly, my laptop becomes much much much more powerful.\n\n---\n\n## Rancher Desktop Setup\n\nInstall [Rancher Desktop](https://rancherdesktop.io/). Be sure to select containerd and not (moby) for container management in Rancher Desktop preferences.\n\n## containerd\n\nThere are a lot of tools that are included with Rancher Desktop for working with containerd through CLI. One of those is `nerdctl` which is basically just a replacement for `docker`. I tried this and I ran into numerous problems. `containerd` isn't Docker. It's not supposed to be or we would just use that. The new approach is to leverage what `containerd` is good at. Find other tools to supplement what I need.\n\n## Kaniko (and buildkit-cli-for-kubectl)\n\nThese are separate things. Kaniko is its own set of tooling for building and deploying containers inside Kubernetes. This is exactly what I need. `buildkit-cli-for-kubectl` is exactly what it sounds like. It's `buildkit` as in Docker; however, it is intended to work with `kubectl` in a kubernetes cluster. I could make this work for me, but I would not be using containerd. I decided Kaniko is the solution more suited for what I want to do. I may still use buildkit because it does sound interesting. It offers daemon support for building with Docker which is interesting in itself. It's just outside what I want right now.\n\n## Private Registry\n\nOne of the things Docker offers that most people take for granted is the local registry that comes with the Desktop. For example, when you use `docker build .`, it creates a container and auto deploys to the local registry. When you type `docker images`, you are being shown what's currently deployed to your local registry. With `containerd`, you do not have this. The solution is to setup a local registry. There are a lot of options\n\n* JFrog Artifactory\n * this is a good option because now it can be used for multiple things)\n* Docker\n * Docker has a container called `registry:2` that can be used\n\n\n## Okteto\n\n[Okteto](https://github.com/okteto/okteto) is the icing here. It's a tool that allows using the k3s cluster for development environments by allowing environments to be deployed as pods to the cluster.","json_metadata":"{\"tags\":[\"blog\"],\"links\":[\"https://rancherdesktop.io/\"],\"app\":\"hiveblog/0.1\",\"format\":\"markdown\",\"description\":\"Development Environment with Rancher Desktop/containerd, Kaniko, Private Registry, and Okteto\"}","created":"2022-08-03T22:25:18","last_update":"2022-08-03T22:25:18","depth":0,"children":1,"last_payout":"1969-12-31T23:59:59","cashout_time":"2022-08-10T22:25:18","total_payout_value":"0.000 HBD","curator_payout_value":"0.000 HBD","pending_payout_value":"0.003 HBD","promoted":"0.000 HBD","replies":[],"body_length":2553,"author_reputation":17895283021,"parent_author":"","parent_permlink":"blog","url":"/blog/@timesheets/development-environment-with-rancher-desktop-containerd-kaniko-private-registry-and-okteto","root_title":"Development Environment with Rancher Desktop/containerd, Kaniko, Private Registry, and Okteto","beneficiaries":[],"max_accepted_payout":"1000000.000 HBD","percent_hbd":10000,"id":115410843,"author_rewards":0,"max_cashout_time":"1969-12-31T23:59:59","reward_weight":10000,"root_author":"timesheets","root_permlink":"development-environment-with-rancher-desktop-containerd-kaniko-private-registry-and-okteto","allow_replies":true,"allow_votes":true,"allow_curation_rewards":true,"reblogged_by":[],"net_votes":1,"children_abs_rshares":0,"total_pending_payout_value":"0.000 HBD","total_vote_weight":3806606280,"vote_rshares":3806606280,"net_rshares":3806606280,"abs_rshares":3806606280,"active_votes":[{"percent":10000,"reputation":17895283021,"rshares":3806606280,"time":"2022-08-03T23:27:45","voter":"timesheets","weight":3806606280}]}
This is the Pull Request with the relevant changes.