Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'Web' files to TypeScript #37590

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/actions/javascript/bumpVersion/index.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this file was changed

Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 13 additions & 9 deletions web/proxy.js → web/proxy.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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;

Expand All @@ -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, '/');
}
Expand All @@ -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);
});

Expand Down
Loading