Browse Source

feat(server): Use default Channel if none specified

Michael Bromley 7 years ago
parent
commit
36cbefe90d

+ 1 - 3
server/src/api/common/request-context.service.ts

@@ -51,14 +51,12 @@ export class RequestContextService {
 
 
     private getChannelToken(req: Request): string {
     private getChannelToken(req: Request): string {
         const tokenKey = this.configService.channelTokenKey;
         const tokenKey = this.configService.channelTokenKey;
-        let channelToken: string;
+        let channelToken = '';
 
 
         if (req && req.query && req.query[tokenKey]) {
         if (req && req.query && req.query[tokenKey]) {
             channelToken = req.query[tokenKey];
             channelToken = req.query[tokenKey];
         } else if (req && req.headers && req.headers[tokenKey]) {
         } else if (req && req.headers && req.headers[tokenKey]) {
             channelToken = req.headers[tokenKey] as string;
             channelToken = req.headers[tokenKey] as string;
-        } else {
-            throw new NoValidChannelError();
         }
         }
         return channelToken;
         return channelToken;
     }
     }

+ 4 - 0
server/src/service/services/channel.service.ts

@@ -46,6 +46,10 @@ export class ChannelService {
      * Given a channel token, returns the corresponding Channel if it exists.
      * Given a channel token, returns the corresponding Channel if it exists.
      */
      */
     getChannelFromToken(token: string): Channel {
     getChannelFromToken(token: string): Channel {
+        if (this.allChannels.length === 1 || token === '') {
+            // there is only the default channel, so return it
+            return this.getDefaultChannel();
+        }
         const channel = this.allChannels.find(c => c.token === token);
         const channel = this.allChannels.find(c => c.token === token);
         if (!channel) {
         if (!channel) {
             throw new InternalServerError(`error.channel-not-found`, { token });
             throw new InternalServerError(`error.channel-not-found`, { token });