-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (35 loc) · 1.27 KB
/
Copy pathserver.js
File metadata and controls
40 lines (35 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// include dependencies
const dotenv = require("dotenv");
const express = require("express");
const { createProxyMiddleware } = require("http-proxy-middleware");
var cors = require("cors");
dotenv.config();
//Note that some EasyPost endpoints require a production API Key, such as the /carrier_accounts endpoint.
let authKey = process.env.EP_PRODUCTION_KEY;
// let authKey = process.env.EP_PRODUCTION_KEY;
// proxy middleware options
/** @type {import('http-proxy-middleware/dist/types').Options} */
const options = {
target: "https://api.easypost.com/v2", // target host
changeOrigin: true, // needed for virtual hosted sites
origin: "https://easytools-spa.netlify.app",
ws: true, // proxy websockets
auth: authKey,
logLevel: "debug",
pathRewrite: {
"^/api/old-path": "/api/new-path", // rewrite path
"^/api/remove/path": "/path", // remove base path
},
router: {
// when request.headers.host == 'dev.localhost:3000',
// override target 'http://www.example.org' to 'http://localhost:8000'
"dev.localhost:3000": "http://localhost:8000",
},
};
// create the proxy (without context)
const exampleProxy = createProxyMiddleware(options);
// mount `exampleProxy` in web server
const app = express();
app.use(cors());
app.use("/", exampleProxy);
app.listen(3000);