0.1.0 • Published 5 months ago
api-proxy.js v0.1.0
api-proxy.js
api-proxy.js is an easy-to-use Node.js service proxy that serves as a communication bridge between internal and external networks without affecting business logic.
Introduction
api-proxy.js is a proxy service used to forward external API requests to the internal network and return the response. It relies on socket.io, socket.io-client, and express.
Service Overview
Service | Name | Deployment Location | Function |
---|---|---|---|
proxy | Proxy Service | External Server | Forwards external API requests to the internal network and returns the response |
server | Internal Request Service | Internal Server | Used to request internal API services |
client | External Access Service | Request Service | Receiving end of external access API services |
Installation
Install using npm:
npm install socket.io socket.io-client express api-proxy.js
Configuration
{
"clientToken": "client", // client, proxy
"proxyHost": "http://localhost:8000", // client, server
"secretKey": "123456", // client, server, proxy
"serverToken": "server" // server, proxy
}
Usage
proxy
import { createProxy } from "api-proxy.js"; import express from "express"; export default function (config = {}) { const { clientToken, proxyHost, secretKey } = config; const app = express(); app.use( createProxy({ clientToken, proxyHost, secretKey, }) ); app.listen(8000, () => { console.log(`proxy is running at http://localhost:8000`); }); }
server
import { createServer } from "api-proxy.js"; export default function (config = {}) { const { serverToken, proxyHost, secretKey } = config; createServer( { serverToken, proxyHost, secretKey, }, async (actions) => { // actions from client // do something ... return { // response }; } ); }
client
import { createClient } from "api-proxy.js"; import express from "express"; export default function (config = {}) { const { clientToken, proxyHost, secretKey } = config; const app = express(); app.use( createClient({ clientToken, proxyHost, secretKey, actionHandler: (req) => { // do something ... return { // actions to client }; }, responseHandler: (res, result) => { // do something ... res.json({ // ... }); }, }) ); app.listen(8008, () => { console.log("client is running at http://localhost:8008"); }); }
0.1.0
5 months ago
0.0.16
5 months ago
0.0.15
5 months ago
0.0.14
5 months ago
0.0.13
5 months ago
0.0.12
5 months ago
0.0.11
5 months ago
0.0.10
5 months ago
0.0.9
5 months ago
0.0.8
5 months ago
0.0.7
5 months ago
0.0.6
5 months ago
0.0.5
5 months ago
0.0.4
5 months ago
0.0.3
5 months ago
0.0.2
5 months ago
0.0.1
5 months ago
0.0.0
5 months ago