add proxy
This commit is contained in:
parent
ce6f536791
commit
91a67178bb
|
@ -15,6 +15,7 @@
|
|||
"cors": "2.8.5",
|
||||
"express": "^4.14.0",
|
||||
"express-fileupload": "1.1.6",
|
||||
"express-http-proxy": "1.6.0",
|
||||
"express-session": "1.17.0",
|
||||
"ramda": "0.26.1",
|
||||
"shortid": "2.2.15",
|
||||
|
|
|
@ -3,6 +3,7 @@ import * as shortid from "shortid"
|
|||
import * as fileUpload from "express-fileupload"
|
||||
import * as R from "ramda"
|
||||
import * as cors from "cors"
|
||||
import * as proxy from "express-http-proxy"
|
||||
import axios from "axios"
|
||||
|
||||
const SIAD_ENDPOINT = "http://localhost:9980"
|
||||
|
@ -71,6 +72,19 @@ export class Server {
|
|||
// siafile
|
||||
this.app.post("/siafile", this.postSiaFile)
|
||||
// linkfile
|
||||
this.app.get(
|
||||
"/linkfile/:hash",
|
||||
proxy("http://localhost:9980/renter/sialink", {
|
||||
proxyReqOptDecorator: (opts, _) => {
|
||||
opts.headers["User-Agent"] = "Sia-Agent"
|
||||
return opts
|
||||
},
|
||||
proxyReqPathResolver: req => {
|
||||
const { hash } = req.params
|
||||
return `/renter/sialink/${hash}`
|
||||
}
|
||||
})
|
||||
)
|
||||
this.app.post("/linkfile", this.handleLinkUpload)
|
||||
}
|
||||
|
||||
|
@ -85,7 +99,6 @@ export class Server {
|
|||
const uid = shortid.generate()
|
||||
console.log("uid:", uid)
|
||||
try {
|
||||
// TODO: add uuid so we don't collide
|
||||
const { data } = await siad.post(
|
||||
`/renter/linkfile/linkfiles/${uid}`,
|
||||
fileToUpload.data,
|
||||
|
|
25
yarn.lock
25
yarn.lock
|
@ -3765,7 +3765,7 @@ debug@3.1.0, debug@=3.1.0:
|
|||
dependencies:
|
||||
ms "2.0.0"
|
||||
|
||||
debug@^3.1.0, debug@^3.2.6:
|
||||
debug@^3.0.1, debug@^3.1.0, debug@^3.2.6:
|
||||
version "3.2.6"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
|
||||
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
|
||||
|
@ -4146,7 +4146,7 @@ es6-iterator@~2.0.3:
|
|||
es5-ext "^0.10.35"
|
||||
es6-symbol "^3.1.1"
|
||||
|
||||
es6-promise@^4.0.3:
|
||||
es6-promise@^4.0.3, es6-promise@^4.1.1:
|
||||
version "4.2.8"
|
||||
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a"
|
||||
integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==
|
||||
|
@ -4275,6 +4275,15 @@ express-fileupload@1.1.6:
|
|||
dependencies:
|
||||
busboy "^0.3.1"
|
||||
|
||||
express-http-proxy@1.6.0:
|
||||
version "1.6.0"
|
||||
resolved "https://registry.yarnpkg.com/express-http-proxy/-/express-http-proxy-1.6.0.tgz#8672b1093cc96b8a93e8e3da948dd111a668ef22"
|
||||
integrity sha512-7Re6Lepg96NA2wiv7DC5csChAScn4K76/UgYnC71XiITCT1cgGTJUGK6GS0pIixudg3Fbx3Q6mmEW3mZv5tHFQ==
|
||||
dependencies:
|
||||
debug "^3.0.1"
|
||||
es6-promise "^4.1.1"
|
||||
raw-body "^2.3.0"
|
||||
|
||||
express-session@1.17.0:
|
||||
version "1.17.0"
|
||||
resolved "https://registry.yarnpkg.com/express-session/-/express-session-1.17.0.tgz#9b50dbb5e8a03c3537368138f072736150b7f9b3"
|
||||
|
@ -5011,7 +5020,7 @@ http-errors@1.7.2:
|
|||
statuses ">= 1.5.0 < 2"
|
||||
toidentifier "1.0.0"
|
||||
|
||||
http-errors@~1.7.2:
|
||||
http-errors@1.7.3, http-errors@~1.7.2:
|
||||
version "1.7.3"
|
||||
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.7.3.tgz#6c619e4f9c60308c38519498c14fbb10aacebb06"
|
||||
integrity sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw==
|
||||
|
@ -7956,6 +7965,16 @@ raw-body@2.4.0:
|
|||
iconv-lite "0.4.24"
|
||||
unpipe "1.0.0"
|
||||
|
||||
raw-body@^2.3.0:
|
||||
version "2.4.1"
|
||||
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.4.1.tgz#30ac82f98bb5ae8c152e67149dac8d55153b168c"
|
||||
integrity sha512-9WmIKF6mkvA0SLmA2Knm9+qj89e+j1zqgyn8aXGd7+nAduPoqgI9lO57SAZNn/Byzo5P7JhXTyg9PzaJbH73bA==
|
||||
dependencies:
|
||||
bytes "3.1.0"
|
||||
http-errors "1.7.3"
|
||||
iconv-lite "0.4.24"
|
||||
unpipe "1.0.0"
|
||||
|
||||
rc@^1.0.1, rc@^1.1.6, rc@^1.2.7:
|
||||
version "1.2.8"
|
||||
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed"
|
||||
|
|
Reference in New Issue