Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3509812
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/server/src/server.js b/server/src/server.js
index 6bcdc3b72..de93f6556 100644
--- a/server/src/server.js
+++ b/server/src/server.js
@@ -1,137 +1,150 @@
// @flow
import cluster from 'cluster';
import cookieParser from 'cookie-parser';
import express from 'express';
import expressWs from 'express-ws';
import os from 'os';
import './cron/cron';
import { migrate } from './database/migrations';
import { jsonEndpoints } from './endpoints';
import { emailSubscriptionResponder } from './responders/comm-landing-responders';
import {
jsonHandler,
httpGetHandler,
downloadHandler,
htmlHandler,
uploadHandler,
} from './responders/handlers';
import landingHandler from './responders/landing-handler';
import { errorReportDownloadResponder } from './responders/report-responders';
import {
createNewVersionResponder,
markVersionDeployedResponder,
} from './responders/version-responders';
import { websiteResponder } from './responders/website-responders';
import { onConnection } from './socket/socket';
import {
multerProcessor,
multimediaUploadResponder,
uploadDownloadResponder,
} from './uploads/uploads';
-import { getSquadCalURLFacts, getLandingURLFacts } from './utils/urls';
+import {
+ getSquadCalURLFacts,
+ getLandingURLFacts,
+ getCommAppURLFacts,
+} from './utils/urls';
const squadCalBaseRoutePath = getSquadCalURLFacts().baseRoutePath;
const landingBaseRoutePath = getLandingURLFacts().baseRoutePath;
+const commAppBaseRoutePath = getCommAppURLFacts().baseRoutePath;
+
+const compiledFolderOptions =
+ process.env.NODE_ENV === 'development'
+ ? undefined
+ : { maxAge: '1y', immutable: true };
if (cluster.isMaster) {
(async () => {
const didMigrationsSucceed: boolean = await migrate();
if (!didMigrationsSucceed) {
// The following line uses exit code 2 to ensure nodemon exits
// in a dev environment, instead of restarting. Context provided
// in https://github.com/remy/nodemon/issues/751
process.exit(2);
}
const cpuCount = os.cpus().length;
for (let i = 0; i < cpuCount; i++) {
cluster.fork();
}
})();
cluster.on('exit', () => cluster.fork());
} else {
const server = express();
expressWs(server);
server.use(express.json({ limit: '50mb' }));
server.use(cookieParser());
- const squadCalRouter = express.Router();
- squadCalRouter.use('/images', express.static('images'));
- squadCalRouter.use('/fonts', express.static('fonts'));
- squadCalRouter.use('/misc', express.static('misc'));
- squadCalRouter.use(
- '/.well-known',
- express.static(
- '.well-known',
- // Necessary for apple-app-site-association file
- {
- setHeaders: res => res.setHeader('Content-Type', 'application/json'),
- },
- ),
- );
- const compiledFolderOptions =
- process.env.NODE_ENV === 'development'
- ? undefined
- : { maxAge: '1y', immutable: true };
- squadCalRouter.use(
- '/compiled',
- express.static('app_compiled', compiledFolderOptions),
- );
- squadCalRouter.use('/', express.static('icons'));
-
- 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),
+ const setupAppRouter = router => {
+ 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'));
- squadCalRouter.get(
- '/create_version/:deviceType/:codeVersion',
- httpGetHandler(createNewVersionResponder),
- );
- squadCalRouter.get(
- '/mark_version_deployed/:deviceType/:codeVersion',
- httpGetHandler(markVersionDeployedResponder),
- );
+ 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),
+ );
+ }
- squadCalRouter.get(
- '/download_error_report/:reportID',
- downloadHandler(errorReportDownloadResponder),
- );
- squadCalRouter.get(
- '/upload/:uploadID/:secret',
- 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
- squadCalRouter.ws('/ws', onConnection);
- squadCalRouter.get('*', htmlHandler(websiteResponder));
+ // $FlowFixMe express-ws has side effects that can't be typed
+ router.ws('/ws', onConnection);
+ router.get('*', htmlHandler(websiteResponder));
- squadCalRouter.post(
- '/upload_multimedia',
- multerProcessor,
- uploadHandler(multimediaUploadResponder),
- );
+ router.post(
+ '/upload_multimedia',
+ multerProcessor,
+ uploadHandler(multimediaUploadResponder),
+ );
+ };
+ const squadCalRouter = express.Router();
+ setupAppRouter(squadCalRouter);
server.use(squadCalBaseRoutePath, squadCalRouter);
+ const commAppRouter = express.Router();
+ setupAppRouter(commAppRouter);
+ server.use(commAppBaseRoutePath, commAppRouter);
+
const landingRouter = express.Router();
landingRouter.use('/images', express.static('images'));
landingRouter.use('/fonts', express.static('fonts'));
landingRouter.use(
'/compiled',
express.static('landing_compiled', compiledFolderOptions),
);
landingRouter.use('/', express.static('landing_icons'));
landingRouter.post('/subscribe_email', emailSubscriptionResponder);
landingRouter.get('*', landingHandler);
server.use(landingBaseRoutePath, landingRouter);
server.listen(parseInt(process.env.PORT, 10) || 3000, 'localhost');
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Dec 23, 8:34 AM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2690645
Default Alt Text
(6 KB)
Attached To
Mode
rCOMM Comm
Attached
Detach File
Event Timeline
Log In to Comment