Revert proxy handler
This commit is contained in:
parent
92107e1b8f
commit
34851a7078
|
@ -1,4 +1,5 @@
|
||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
|
import * as AxiosLogger from 'axios-logger'
|
||||||
import cors from "cors"
|
import cors from "cors"
|
||||||
import express, { Request, Response } from "express"
|
import express, { Request, Response } from "express"
|
||||||
import fileUpload, { UploadedFile } from "express-fileupload"
|
import fileUpload, { UploadedFile } from "express-fileupload"
|
||||||
|
@ -9,7 +10,6 @@ import R from "ramda"
|
||||||
import shortid from "shortid"
|
import shortid from "shortid"
|
||||||
import { Logger } from "winston"
|
import { Logger } from "winston"
|
||||||
import logger from "./logger"
|
import logger from "./logger"
|
||||||
import * as AxiosLogger from 'axios-logger';
|
|
||||||
|
|
||||||
|
|
||||||
const MAX_UPLOAD_FILESIZE = 1000 * 1024 * 1024
|
const MAX_UPLOAD_FILESIZE = 1000 * 1024 * 1024
|
||||||
|
@ -84,9 +84,22 @@ export class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
private configureRoutes() {
|
private configureRoutes() {
|
||||||
this.app.get("/sialink/:hash", this.handleSialinkGET.bind(this))
|
|
||||||
this.app.post("/siafile", this.handleSiafilePOST.bind(this))
|
this.app.post("/siafile", this.handleSiafilePOST.bind(this))
|
||||||
this.app.post("/linkfile", this.handleLinkfilePOST.bind(this))
|
this.app.post("/linkfile", this.handleLinkfilePOST.bind(this))
|
||||||
|
|
||||||
|
this.app.get(
|
||||||
|
"/sialink/: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}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async verifyConnection(): Promise<string | null> {
|
private async verifyConnection(): Promise<string | null> {
|
||||||
|
@ -100,19 +113,6 @@ export class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleSialinkGET() {
|
|
||||||
return proxy(`${SIAD_ENDPOINT}/renter/sialink`, {
|
|
||||||
proxyReqOptDecorator: (opts, _) => {
|
|
||||||
opts.headers["User-Agent"] = "Sia-Agent"
|
|
||||||
return opts
|
|
||||||
},
|
|
||||||
proxyReqPathResolver: req => {
|
|
||||||
const { hash } = req.params
|
|
||||||
return `/renter/sialink/${hash}`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleLinkfilePOST(req: Request, res: Response): Promise<Response> {
|
private async handleLinkfilePOST(req: Request, res: Response): Promise<Response> {
|
||||||
const file = selectFile(req) as UploadedFile
|
const file = selectFile(req) as UploadedFile
|
||||||
const uid = shortid.generate()
|
const uid = shortid.generate()
|
||||||
|
|
Reference in New Issue