tweaking backend, considering arch...

master
lza_menace 2 years ago
parent 6ed041d22e
commit 8b9e437134

@ -13,6 +13,7 @@
"@types/express": "^4.17.17",
"@types/morgan": "^1.9.4",
"axios": "^1.4.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"morgan": "^1.10.0",
"nodemon": "^2.0.22",
@ -452,6 +453,14 @@
"node": ">=0.3.1"
}
},
"node_modules/dotenv": {
"version": "16.0.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
"engines": {
"node": ">=12"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
@ -1664,6 +1673,11 @@
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A=="
},
"dotenv": {
"version": "16.0.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",

@ -15,6 +15,7 @@
"@types/express": "^4.17.17",
"@types/morgan": "^1.9.4",
"axios": "^1.4.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"morgan": "^1.10.0",
"nodemon": "^2.0.22",

@ -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;

@ -1,4 +1,3 @@
/** source/server.ts */
import http from 'http';
import express, { Express } from 'express';
import morgan from 'morgan';
@ -9,7 +8,6 @@ const router: Express = express();
router.use(morgan('dev'));
router.use(express.urlencoded({ extended: false }));
router.use(express.json());
router.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'origin, X-Requested-With, Content-Type, Accept, Authorization');
@ -19,9 +17,7 @@ router.use((req, res, next) => {
}
next();
});
router.use('/', routes);
router.use((req, res, next) => {
const error = new Error('not found');
return res.status(404).json({

@ -30,6 +30,9 @@ services:
restart: unless-stopped
depends_on:
- monerod
ports:
- 127.0.0.1:8081:8081
- 127.0.0.1:8080:8080
command:
--scan-threads 4 --rest-threads 4 --rest-server http://0.0.0.0:8080 --admin-rest-server http://0.0.0.0:8081 --log-level 1 --daemon=tcp://monerod:18082 --sub=tcp://monerod:18083 --confirm-external-bind
<<: *log-config

Loading…
Cancel
Save