From 57370c83d1ea54e9a7f4753bcdd47f7fc42e58de Mon Sep 17 00:00:00 2001 From: Filip Solecki Date: Fri, 1 Mar 2024 10:10:16 +0100 Subject: [PATCH 1/3] Migrate web proxy to TS --- config/{proxyConfig.js => proxyConfig.ts} | 2 +- package.json | 2 +- web/{proxy.js => proxy.ts} | 22 +++++++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) rename config/{proxyConfig.js => proxyConfig.ts} (92%) rename web/{proxy.js => proxy.ts} (78%) diff --git a/config/proxyConfig.js b/config/proxyConfig.ts similarity index 92% rename from config/proxyConfig.js rename to config/proxyConfig.ts index fa09c436461f..6a74d145df85 100644 --- a/config/proxyConfig.js +++ b/config/proxyConfig.ts @@ -3,7 +3,7 @@ * We only specify for staging URLs as API requests are sent to the production * servers by default. */ -module.exports = { +export default { STAGING: '/staging/', STAGING_SECURE: '/staging-secure/', }; diff --git a/package.json b/package.json index e3c23d4538d3..e757f000f5be 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "ipad-sm": "concurrently \"npx react-native run-ios --simulator=\\\"iPad Pro (11-inch) (4th generation)\\\" --mode=\\\"DebugDevelopment\\\" --scheme=\\\"New Expensify Dev\\\"\"", "start": "npx react-native start", "web": "scripts/set-pusher-suffix.sh && concurrently npm:web-proxy npm:web-server", - "web-proxy": "ts-node web/proxy.js", + "web-proxy": "ts-node web/proxy.ts", "web-server": "webpack-dev-server --open --config config/webpack/webpack.dev.js", "build": "webpack --config config/webpack/webpack.common.js --env envFile=.env.production", "build-staging": "webpack --config config/webpack/webpack.common.js --env envFile=.env.staging", diff --git a/web/proxy.js b/web/proxy.ts similarity index 78% rename from web/proxy.js rename to web/proxy.ts index 0d82ae60b678..130f5a67e51a 100644 --- a/web/proxy.js +++ b/web/proxy.ts @@ -1,7 +1,10 @@ -const http = require('http'); -const https = require('https'); -const proxyConfig = require('../config/proxyConfig'); -require('dotenv').config(); +import dotenv from 'dotenv'; +import http from 'http'; +import type {IncomingMessage, ServerResponse} from 'http'; +import https from 'https'; +import proxyConfig from '../config/proxyConfig'; + +dotenv.config(); if (process.env.USE_WEB_PROXY === 'false') { process.stdout.write('Skipping proxy as USE_WEB_PROXY was set to false.\n'); @@ -20,7 +23,7 @@ console.log(`Creating proxy with host: ${host} for production API and ${stagingH * possible to work on the app within a limited development * environment that has no local API. */ -const server = http.createServer((request, response) => { +const server = http.createServer((request: IncomingMessage, response: ServerResponse) => { let hostname = host; let requestPath = request.url; @@ -37,10 +40,10 @@ const server = http.createServer((request, response) => { * /receipts/w_... => request sent to production server * /staging/chat-attachments/46545... => request sent to staging server */ - if (request.url.startsWith(proxyConfig.STAGING_SECURE)) { + if (request.url?.startsWith(proxyConfig.STAGING_SECURE)) { hostname = stagingSecureHost; requestPath = request.url.replace(proxyConfig.STAGING_SECURE, '/'); - } else if (request.url.startsWith(proxyConfig.STAGING)) { + } else if (request.url?.startsWith(proxyConfig.STAGING)) { hostname = stagingHost; requestPath = request.url.replace(proxyConfig.STAGING, '/'); } @@ -52,14 +55,15 @@ const server = http.createServer((request, response) => { headers: { ...request.headers, host: hostname, - 'user-agent': request.headers['user-agent'].concat(' Development-NewDot/1.0'), + // eslint-disable-next-line @typescript-eslint/naming-convention + 'user-agent': request.headers['user-agent']?.concat(' Development-NewDot/1.0'), }, port: 443, }); request.pipe(proxyRequest); proxyRequest.on('response', (proxyResponse) => { - response.writeHead(proxyResponse.statusCode, proxyResponse.headers); + response.writeHead(proxyResponse.statusCode ?? 0, proxyResponse.headers); proxyResponse.pipe(response); }); From 3c5b6a272a89cda8d9a17d50008f24a84b4ea91d Mon Sep 17 00:00:00 2001 From: Filip Solecki Date: Fri, 1 Mar 2024 10:22:24 +0100 Subject: [PATCH 2/3] Fix GH actions --- .github/actions/javascript/bumpVersion/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/actions/javascript/bumpVersion/index.js b/.github/actions/javascript/bumpVersion/index.js index d17760baa91f..8fe84446ba82 100644 --- a/.github/actions/javascript/bumpVersion/index.js +++ b/.github/actions/javascript/bumpVersion/index.js @@ -2657,12 +2657,17 @@ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`) // Coercion. // Extract anything that could conceivably be a part of a valid semver -createToken('COERCE', `${'(^|[^\\d])' + +createToken('COERCEPLAIN', `${'(^|[^\\d])' + '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` + `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` + - `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` + + `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`) +createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`) +createToken('COERCEFULL', src[t.COERCEPLAIN] + + `(?:${src[t.PRERELEASE]})?` + + `(?:${src[t.BUILD]})?` + `(?:$|[^\\d])`) createToken('COERCERTL', src[t.COERCE], true) +createToken('COERCERTLFULL', src[t.COERCEFULL], true) // Tilde ranges. // Meaning is "reasonably at or greater than" From c19ccde1e07006228b2eb26752c03680e5580564 Mon Sep 17 00:00:00 2001 From: Filip Solecki Date: Fri, 1 Mar 2024 10:25:34 +0100 Subject: [PATCH 3/3] Revert unnecessary changes --- config/{proxyConfig.ts => proxyConfig.js} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename config/{proxyConfig.ts => proxyConfig.js} (92%) diff --git a/config/proxyConfig.ts b/config/proxyConfig.js similarity index 92% rename from config/proxyConfig.ts rename to config/proxyConfig.js index 6a74d145df85..fa09c436461f 100644 --- a/config/proxyConfig.ts +++ b/config/proxyConfig.js @@ -3,7 +3,7 @@ * We only specify for staging URLs as API requests are sent to the production * servers by default. */ -export default { +module.exports = { STAGING: '/staging/', STAGING_SECURE: '/staging-secure/', };