Reorganize server files and address TODO comments
Changes:
- Remove unneeded dependencies from package.json
- Remove unneeded async build() methods from services
- Use constructor as often as possible
- Rename and move storage services for clarity
- creds.ts -> accounts.ts, and creds.json -> accounts.json
- admin-config.ts -> admin-account.ts
- vault.ts -> signing-keys.ts
- Rename ws.ts to websocket-server.ts for clarity and consistency
- Make WebSocketServer initialize using constructor and bind server upgrade to WebSocketServer.upgrade
- Remove unused send-account-message endpoint from account-router.ts
- Set issuer and audience claims for JWT
- Create new utils/jwt.ts file to remove code duplication for JWT signing and verifying
- Delete utils.ts and merge it with jami-swig.ts
- Handle potentially undefined types in jami-swig.ts
- Replace hard to read one-liners with functions in jami-swig.ts
- Rename types in jami-swig.ts for consistency with daemon
- Remove handled/answered TODO comments
- Remove TODO comment about using .env for jamid.node as it does not work for require()
GitLab: #87
Change-Id: I1e5216ffa79ea34dd7e9b61540fb7e37d1f66c9f
diff --git a/server/src/app.ts b/server/src/app.ts
index f6086cd..27e6e99 100644
--- a/server/src/app.ts
+++ b/server/src/app.ts
@@ -22,7 +22,6 @@
import log from 'loglevel';
import { Service } from 'typedi';
-import { bindWebRTCCallbacks } from './handlers/webrtc-handler.js';
import { checkAdminSetup } from './middleware/setup.js';
import { accountRouter } from './routers/account-router.js';
import { authRouter } from './routers/auth-router.js';
@@ -32,44 +31,43 @@
import { defaultModeratorsRouter } from './routers/default-moderators-router.js';
import { nameserverRouter } from './routers/nameserver-router.js';
import { setupRouter } from './routers/setup-router.js';
+import { bindWebRTCCallbacks } from './websocket/webrtc-handler.js';
@Service()
export class App {
- async build() {
- const app = express();
+ app = express();
+ constructor() {
// Setup middleware
- app.use(helmet());
- app.use(cors());
- app.use(json());
+ this.app.use(helmet());
+ this.app.use(cors());
+ this.app.use(json());
// Enforce admin setup
- app.use('/setup', setupRouter);
- app.use(checkAdminSetup);
+ this.app.use('/setup', setupRouter);
+ this.app.use(checkAdminSetup);
// Setup routing
- app.use('/auth', authRouter);
- app.use('/account', accountRouter);
- app.use('/contacts', contactsRouter);
- app.use('/default-moderators', defaultModeratorsRouter);
- app.use('/conversations', conversationRouter);
- app.use('/calls', callRouter);
- app.use('/ns', nameserverRouter);
+ this.app.use('/auth', authRouter);
+ this.app.use('/account', accountRouter);
+ this.app.use('/contacts', contactsRouter);
+ this.app.use('/default-moderators', defaultModeratorsRouter);
+ this.app.use('/conversations', conversationRouter);
+ this.app.use('/calls', callRouter);
+ this.app.use('/ns', nameserverRouter);
// Setup WebSocket callbacks
bindWebRTCCallbacks();
// Setup 404 error handling
- app.use((_req, res) => {
+ this.app.use((_req, res) => {
res.sendStatus(HttpStatusCode.NotFound);
});
// Setup internal error handling
- app.use((err: Error, _req: Request, res: Response, _next: NextFunction) => {
+ this.app.use((err: Error, _req: Request, res: Response, _next: NextFunction) => {
log.error(err);
res.status(HttpStatusCode.InternalServerError).send(err.message);
});
-
- return app;
}
}