refactor: remove deprecated url.parse() method (#7751)

This commit is contained in:
Corey
2022-01-06 09:26:00 -05:00
committed by GitHub
parent a43638f300
commit a5ffb95022
9 changed files with 74 additions and 36 deletions

View File

@@ -1,5 +1,4 @@
const Parse = require('parse/node').Parse;
const url = require('url');
const path = require('path');
// These methods handle batch requests.
const batchPath = '/batch';
@@ -11,11 +10,12 @@ function mountOnto(router) {
});
}
function parseURL(URL) {
if (typeof URL === 'string') {
return url.parse(URL);
function parseURL(urlString) {
try {
return new URL(urlString);
} catch(error) {
return undefined;
}
return undefined;
}
function makeBatchRoutingPathFunction(originalUrl, serverURL, publicServerURL) {
@@ -33,9 +33,9 @@ function makeBatchRoutingPathFunction(originalUrl, serverURL, publicServerURL) {
return path.posix.join('/', requestPath.slice(apiPrefix.length));
};
if (serverURL && publicServerURL && serverURL.path != publicServerURL.path) {
const localPath = serverURL.path;
const publicPath = publicServerURL.path;
if (serverURL && publicServerURL && serverURL.pathname != publicServerURL.pathname) {
const localPath = serverURL.pathname;
const publicPath = publicServerURL.pathname;
// Override the api prefix
apiPrefix = localPath;