tweaking backend, considering arch...
parent
6ed041d22e
commit
8b9e437134
@ -1,30 +0,0 @@
|
||||
{
|
||||
"name": "monero-lws-backend",
|
||||
"version": "1.0.0",
|
||||
"engines": {
|
||||
"node": "16.x"
|
||||
},
|
||||
"description": "",
|
||||
"main": "serve.ts",
|
||||
"scripts": {
|
||||
"serve": "node --max_old_space_size=128 --optimize_for_size src/server.js",
|
||||
"start": "concurrently npm:scrape npm:serve --restart-tries -1 --restart-after 5000",
|
||||
"stop": "pkill -e -f concurrently && pkill -e -f scrape",
|
||||
"scrape": "node --max_old_space_size=128 --optimize_for_size src/scraper.js",
|
||||
"resync": "echo Deleting data in 5 seconds... && sleep 5 && rm storage/*.txt",
|
||||
"wipe": "echo Deleting data in 5 seconds... && sleep 5 && npm run resync && storage/*.db"
|
||||
},
|
||||
"author": "lza_menace",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^7.4.5",
|
||||
"bignumber.js": "^9.0.1",
|
||||
"concurrently": "^6.5.0",
|
||||
"dotenv": "^10.0.0",
|
||||
"ethers": "^5.6.9",
|
||||
"express": "^4.17.1",
|
||||
"node-fetch": "^3.2.9",
|
||||
"sqlite3": "^5.0.2"
|
||||
}
|
||||
}
|
||||
|
@ -1,79 +1,44 @@
|
||||
require('dotenv').config()
|
||||
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
import axios, { Axios, AxiosResponse } from 'axios';
|
||||
|
||||
interface Post {
|
||||
userId: Number;
|
||||
id: Number;
|
||||
title: String;
|
||||
body: String;
|
||||
}
|
||||
const LWS_URL = process.env.LWS_URL ?? "http://127.0.0.1:8080";
|
||||
const LWS_ADMIN_URL = process.env.LWS_ADMIN_URL ?? "http://127.0.0.1:8081";
|
||||
|
||||
// getting all posts
|
||||
const getPosts = async (req: Request, res: Response, next: NextFunction) => {
|
||||
// get some posts
|
||||
let result: AxiosResponse = await axios.get(`https://jsonplaceholder.typicode.com/posts`);
|
||||
let posts: [Post] = result.data;
|
||||
return res.status(200).json({
|
||||
message: posts
|
||||
});
|
||||
};
|
||||
// interface Auth {
|
||||
// auth: String;
|
||||
// }
|
||||
|
||||
// getting a single post
|
||||
const getPost = async (req: Request, res: Response, next: NextFunction) => {
|
||||
// get the post id from the req
|
||||
let id: string = req.params.id;
|
||||
// get the post
|
||||
let result: AxiosResponse = await axios.get(`https://jsonplaceholder.typicode.com/posts/${id}`);
|
||||
let post: Post = result.data;
|
||||
return res.status(200).json({
|
||||
message: post
|
||||
});
|
||||
};
|
||||
// accept_requests: {"type": "import"|"create", "addresses":[...]}
|
||||
// add_account: {"address": ..., "key": ...}
|
||||
// list_accounts: {}
|
||||
// list_requests: {}
|
||||
// modify_account_status: {"status": "active"|"hidden"|"inactive", "addresses":[...]}
|
||||
// reject_requests: {"type": "import"|"create", "addresses":[...]}
|
||||
// rescan: {"height":..., "addresses":[...]}
|
||||
// webhook_add: {"type":"tx-confirmation", "address":"...", "url":"...", ...} with optional fields:
|
||||
// token: A string to be returned when the webhook is triggered
|
||||
// payment_id: 16 hex characters representing a unique identifier for a transaction
|
||||
// webhook_delete
|
||||
|
||||
// updating a post
|
||||
const updatePost = async (req: Request, res: Response, next: NextFunction) => {
|
||||
// get the post id from the req.params
|
||||
let id: string = req.params.id;
|
||||
// get the data from req.body
|
||||
let title: string = req.body.title ?? null;
|
||||
let body: string = req.body.body ?? null;
|
||||
// update the post
|
||||
let response: AxiosResponse = await axios.put(`https://jsonplaceholder.typicode.com/posts/${id}`, {
|
||||
...(title && { title }),
|
||||
...(body && { body })
|
||||
const listAccounts = async (req: Request, res: Response, next: NextFunction) => {
|
||||
let response: AxiosResponse = await axios.post(`${LWS_ADMIN_URL}/list_accounts`, {
|
||||
"auth": ""
|
||||
});
|
||||
// return response
|
||||
return res.status(200).json({
|
||||
message: response.data
|
||||
});
|
||||
};
|
||||
|
||||
// deleting a post
|
||||
const deletePost = async (req: Request, res: Response, next: NextFunction) => {
|
||||
// get the post id from req.params
|
||||
let id: string = req.params.id;
|
||||
// delete the post
|
||||
let response: AxiosResponse = await axios.delete(`https://jsonplaceholder.typicode.com/posts/${id}`);
|
||||
// return response
|
||||
return res.status(200).json({
|
||||
message: 'post deleted successfully'
|
||||
const getAddressInfo = async (req: Request, res: Response, next: NextFunction) => {
|
||||
let response: AxiosResponse = await axios.post(`${LWS_URL}/get_address_info`, {
|
||||
"address": "",
|
||||
"view_key": ""
|
||||
});
|
||||
};
|
||||
|
||||
// adding a post
|
||||
const addPost = async (req: Request, res: Response, next: NextFunction) => {
|
||||
// get the data from req.body
|
||||
let title: string = req.body.title;
|
||||
let body: string = req.body.body;
|
||||
// add the post
|
||||
let response: AxiosResponse = await axios.post(`https://jsonplaceholder.typicode.com/posts`, {
|
||||
title,
|
||||
body
|
||||
});
|
||||
// return response
|
||||
return res.status(200).json({
|
||||
message: response.data
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default { getPosts, getPost, updatePost, deletePost, addPost };
|
||||
export default { listAccounts, getAddressInfo };
|
||||
|
@ -1,12 +1,8 @@
|
||||
/** source/routes/posts.ts */
|
||||
import express from 'express';
|
||||
import controller from '../interfaces/main';
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/posts', controller.getPosts);
|
||||
router.get('/posts/:id', controller.getPost);
|
||||
router.put('/posts/:id', controller.updatePost);
|
||||
router.delete('/posts/:id', controller.deletePost);
|
||||
router.post('/posts', controller.addPost);
|
||||
router.get('/accounts', controller.listAccounts);
|
||||
router.get('/addressInfo', controller.getAddressInfo);
|
||||
|
||||
export = router;
|
Loading…
Reference in New Issue