public code v1
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
const express = require("express");
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
class Express {
|
||||
#app;
|
||||
#name;
|
||||
#port;
|
||||
|
||||
constructor(port, name = "Service") {
|
||||
this.#app = express();
|
||||
this.#app.use(bodyParser.json());
|
||||
this.#app.use(bodyParser.urlencoded({ extended: true }));
|
||||
this.#name = name;
|
||||
this.#port = port;
|
||||
}
|
||||
|
||||
get app() {
|
||||
return this.#app;
|
||||
}
|
||||
|
||||
get = (path, f) => this.#app.get(path, f);
|
||||
post = (path, f) => this.#app.post(path, f);
|
||||
put = (path, f) => this.#app.put(path, f);
|
||||
delete = (path, f) => this.#app.delete(path, f);
|
||||
|
||||
run = () => {
|
||||
this.#app.listen(this.#port, () =>
|
||||
console.log(`${this.#name} listening on port ${this.#port}`)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.Express = Express;
|
||||
@@ -0,0 +1,56 @@
|
||||
const axios = require("axios");
|
||||
|
||||
function promiseGetRequest(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(url)
|
||||
axios.get(url)
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function promisePostRequest(url, body) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(url, body)
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function promisePutRequest(url, body) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.put(url, body)
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function promiseDeleteRequest(url, body) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.delete(url, { data: body })
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {promiseGetRequest, promisePostRequest, promiseDeleteRequest}
|
||||
Generated
+1019
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "core",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.20.1",
|
||||
"express": "^4.18.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user