Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32236187
D9452.1765222029.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D9452.1765222029.diff
View Options
diff --git a/keyserver/src/keyserver.js b/keyserver/src/keyserver.js
--- a/keyserver/src/keyserver.js
+++ b/keyserver/src/keyserver.js
@@ -56,7 +56,8 @@
(async () => {
await Promise.all([olm.init(), prefetchAllURLFacts(), initENSCache()]);
- const keyserverBaseRoutePath = getKeyserverURLFacts()?.baseRoutePath;
+ const keyserverURLFacts = getKeyserverURLFacts();
+ const keyserverBaseRoutePath = keyserverURLFacts?.baseRoutePath;
const landingBaseRoutePath = getLandingURLFacts()?.baseRoutePath;
const webAppURLFacts = getWebAppURLFacts();
const webAppBaseRoutePath = webAppURLFacts?.baseRoutePath;
@@ -133,66 +134,6 @@
server.use(express.json({ limit: '250mb' }));
server.use(cookieParser());
- const setupAppRouter = router => {
- if (areEndpointMetricsEnabled) {
- router.use(logEndpointMetrics);
- }
- if (corsOptions) {
- router.use(cors(corsOptions));
- }
- router.use('/images', express.static('images'));
- router.use('/fonts', express.static('fonts'));
- router.use('/misc', express.static('misc'));
- router.use(
- '/.well-known',
- express.static(
- '.well-known',
- // Necessary for apple-app-site-association file
- {
- setHeaders: res =>
- res.setHeader('Content-Type', 'application/json'),
- },
- ),
- );
- router.use(
- '/compiled',
- express.static('app_compiled', compiledFolderOptions),
- );
- router.use('/', express.static('icons'));
-
- for (const endpoint in jsonEndpoints) {
- // $FlowFixMe Flow thinks endpoint is string
- const responder = jsonEndpoints[endpoint];
- const expectCookieInvalidation = endpoint === 'log_out';
- router.post(
- `/${endpoint}`,
- jsonHandler(responder, expectCookieInvalidation),
- );
- }
-
- router.get(
- '/download_error_report/:reportID',
- downloadHandler(errorReportDownloadResponder),
- );
- router.get(
- '/upload/:uploadID/:secret',
- downloadHandler(uploadDownloadResponder),
- );
-
- router.get('/invite/:secret', inviteResponder);
-
- // $FlowFixMe express-ws has side effects that can't be typed
- router.ws('/ws', onConnection);
- router.get('/worker/:worker', webWorkerResponder);
- router.get('*', htmlHandler(websiteResponder));
-
- router.post(
- '/upload_multimedia',
- multerProcessor,
- uploadHandler(multimediaUploadResponder),
- );
- };
-
// Note - the order of router declarations matters. On prod we have
// squadCalBaseRoutePath configured to '/', which means it's a catch-all. If
// we call server.use on squadCalRouter first, it will catch all requests
@@ -229,13 +170,83 @@
if (webAppBaseRoutePath) {
const commAppRouter = express.Router();
- setupAppRouter(commAppRouter);
+ commAppRouter.use('/images', express.static('images'));
+ commAppRouter.use('/fonts', express.static('fonts'));
+ commAppRouter.use('/misc', express.static('misc'));
+ commAppRouter.use(
+ '/.well-known',
+ express.static(
+ '.well-known',
+ // Necessary for apple-app-site-association file
+ {
+ setHeaders: res =>
+ res.setHeader('Content-Type', 'application/json'),
+ },
+ ),
+ );
+ commAppRouter.use(
+ '/compiled',
+ express.static('app_compiled', compiledFolderOptions),
+ );
+ commAppRouter.use('/', express.static('icons'));
+
+ commAppRouter.get('/invite/:secret', inviteResponder);
+
+ commAppRouter.get('/worker/:worker', webWorkerResponder);
+
+ if (keyserverURLFacts) {
+ commAppRouter.get(
+ '/upload/:uploadID/:secret',
+ (req: $Request, res: $Response) => {
+ const { uploadID, secret } = req.params;
+ const url = `${keyserverURLFacts.baseDomain}${keyserverURLFacts.basePath}upload/${uploadID}/${secret}`;
+ res.redirect(url);
+ },
+ );
+ }
+
+ commAppRouter.get('*', htmlHandler(websiteResponder));
+
server.use(webAppBaseRoutePath, commAppRouter);
}
if (keyserverBaseRoutePath) {
const squadCalRouter = express.Router();
- setupAppRouter(squadCalRouter);
+ if (areEndpointMetricsEnabled) {
+ squadCalRouter.use(logEndpointMetrics);
+ }
+ if (corsOptions) {
+ squadCalRouter.use(cors(corsOptions));
+ }
+
+ for (const endpoint in jsonEndpoints) {
+ // $FlowFixMe Flow thinks endpoint is string
+ const responder = jsonEndpoints[endpoint];
+ const expectCookieInvalidation = endpoint === 'log_out';
+ squadCalRouter.post(
+ `/${endpoint}`,
+ jsonHandler(responder, expectCookieInvalidation),
+ );
+ }
+
+ squadCalRouter.get(
+ '/download_error_report/:reportID',
+ downloadHandler(errorReportDownloadResponder),
+ );
+ squadCalRouter.get(
+ '/upload/:uploadID/:secret',
+ downloadHandler(uploadDownloadResponder),
+ );
+
+ // $FlowFixMe express-ws has side effects that can't be typed
+ squadCalRouter.ws('/ws', onConnection);
+
+ squadCalRouter.post(
+ '/upload_multimedia',
+ multerProcessor,
+ uploadHandler(multimediaUploadResponder),
+ );
+
server.use(keyserverBaseRoutePath, squadCalRouter);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 8, 7:27 PM (9 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5850108
Default Alt Text
D9452.1765222029.diff (5 KB)
Attached To
Mode
D9452: [keyserver] Separate webapp and keyserver endpoints
Attached
Detach File
Event Timeline
Log In to Comment