Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3394011
D3549.id10833.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D3549.id10833.diff
View Options
diff --git a/server/src/server.js b/server/src/server.js
--- a/server/src/server.js
+++ b/server/src/server.js
@@ -30,12 +30,7 @@
multimediaUploadResponder,
uploadDownloadResponder,
} from './uploads/uploads';
-import {
- getGlobalURLFacts,
- getLandingURLFacts,
- generateAllRoutePaths,
- generateBaseAndCommAppRoutePaths,
-} from './utils/urls';
+import { getGlobalURLFacts, getLandingURLFacts } from './utils/urls';
const { baseRoutePath } = getGlobalURLFacts();
const landingBaseRoutePath = getLandingURLFacts().baseRoutePath;
@@ -62,15 +57,11 @@
server.use(cookieParser());
const router = express.Router();
- for (const routePath of generateAllRoutePaths('images')) {
- router.use(routePath, express.static('images'));
- }
- for (const routePath of generateAllRoutePaths('fonts')) {
- router.use(routePath, express.static('fonts'));
- }
- for (const routePath of generateBaseAndCommAppRoutePaths('misc')) {
- router.use(routePath, express.static('misc'));
- }
+ router.use('/images', express.static('images'));
+ router.use(`${landingBaseRoutePath}images`, express.static('images'));
+ router.use('/fonts', express.static('fonts'));
+ router.use(`${landingBaseRoutePath}fonts`, express.static('fonts'));
+ router.use('/misc', express.static('misc'));
router.use(
'/.well-known',
express.static(
@@ -85,28 +76,25 @@
process.env.NODE_ENV === 'development'
? undefined
: { maxAge: '1y', immutable: true };
- for (const routePath of generateBaseAndCommAppRoutePaths('compiled')) {
- router.use(
- routePath,
- express.static('app_compiled', compiledFolderOptions),
- );
- }
+ router.use(
+ '/compiled',
+ express.static('app_compiled', compiledFolderOptions),
+ );
router.use(
`${landingBaseRoutePath}compiled`,
express.static('landing_compiled', compiledFolderOptions),
);
- for (const routePath of generateBaseAndCommAppRoutePaths('')) {
- router.use(routePath, express.static('icons'));
- }
- router.use(`${landingBaseRoutePath}`, express.static('landing_icons'));
+ router.use('/', express.static('icons'));
+ router.use('/commlanding', express.static('landing_icons'));
for (const endpoint in jsonEndpoints) {
// $FlowFixMe Flow thinks endpoint is string
const responder = jsonEndpoints[endpoint];
const expectCookieInvalidation = endpoint === 'log_out';
- for (const routePath of generateBaseAndCommAppRoutePaths(endpoint)) {
- router.post(routePath, jsonHandler(responder, expectCookieInvalidation));
- }
+ router.post(
+ `/${endpoint}`,
+ jsonHandler(responder, expectCookieInvalidation),
+ );
}
router.post(
@@ -114,41 +102,34 @@
emailSubscriptionResponder,
);
- for (const routePath of generateBaseAndCommAppRoutePaths(
- 'create_version/:deviceType/:codeVersion',
- )) {
- router.get(routePath, httpGetHandler(createNewVersionResponder));
- }
- for (const routePath of generateBaseAndCommAppRoutePaths(
- 'mark_version_deployed/:deviceType/:codeVersion',
- )) {
- router.get(routePath, httpGetHandler(markVersionDeployedResponder));
- }
- for (const routePath of generateBaseAndCommAppRoutePaths(
- 'download_error_report/:reportID',
- )) {
- router.get(routePath, downloadHandler(errorReportDownloadResponder));
- }
- for (const routePath of generateBaseAndCommAppRoutePaths(
- 'upload/:uploadID/:secret',
- )) {
- router.get(routePath, downloadHandler(uploadDownloadResponder));
- }
+ router.get(
+ '/create_version/:deviceType/:codeVersion',
+ httpGetHandler(createNewVersionResponder),
+ );
+ router.get(
+ '/mark_version_deployed/:deviceType/:codeVersion',
+ httpGetHandler(markVersionDeployedResponder),
+ );
+
+ router.get(
+ '/download_error_report/:reportID',
+ downloadHandler(errorReportDownloadResponder),
+ );
+ router.get(
+ '/upload/:uploadID/:secret',
+ downloadHandler(uploadDownloadResponder),
+ );
// $FlowFixMe express-ws has side effects that can't be typed
- router.ws(`${baseRoutePath}ws`, onConnection);
+ router.ws('/ws', onConnection);
router.get(`${landingBaseRoutePath}*`, landingHandler);
router.get('*', htmlHandler(websiteResponder));
- for (const routePath of generateBaseAndCommAppRoutePaths(
- 'upload_multimedia',
- )) {
- router.post(
- routePath,
- multerProcessor,
- uploadHandler(multimediaUploadResponder),
- );
- }
+ router.post(
+ '/upload_multimedia',
+ multerProcessor,
+ uploadHandler(multimediaUploadResponder),
+ );
server.use(baseRoutePath, router);
server.listen(parseInt(process.env.PORT, 10) || 3000, 'localhost');
diff --git a/server/src/utils/urls.js b/server/src/utils/urls.js
--- a/server/src/utils/urls.js
+++ b/server/src/utils/urls.js
@@ -39,25 +39,10 @@
return landingURLFacts;
}
-function generateAllRoutePaths(endpoint: string): string[] {
- const landingBaseRoutePath = landingURLFacts.baseRoutePath;
- const routePaths = generateBaseAndCommAppRoutePaths(endpoint);
- routePaths.push(landingBaseRoutePath + endpoint);
- return routePaths;
-}
-
-function generateBaseAndCommAppRoutePaths(endpoint: string): string[] {
- const { baseRoutePath } = baseURLFacts;
- const commAppBaseRoutePath = commAppURLFacts.basePath;
- return [baseRoutePath + endpoint, commAppBaseRoutePath + endpoint];
-}
-
export {
getGlobalURLFacts,
getSquadCalURLFacts,
getCommAppURLFacts,
getLandingURLFacts,
getAppURLFactsFromRequestURL,
- generateAllRoutePaths,
- generateBaseAndCommAppRoutePaths,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 1, 4:54 PM (21 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2605633
Default Alt Text
D3549.id10833.diff (5 KB)
Attached To
Mode
D3549: Revert "[server] add helper function to generate all route paths"
Attached
Detach File
Event Timeline
Log In to Comment