Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Connect to WS if extensibility or toggles are turned on in Project #40

Closed
codeyogi911 opened this issue Jan 24, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@codeyogi911
Copy link

Hello team,
I am trying to integrate WS with my project and getting the following error when i try to connect.

[CDS] [cds|t1] - ❗️Uncaught TypeError: Cannot read properties of undefined (reading 'startsWith')
[CDS]     at cds_context_model (/Users/shashwatjain/Repos/mymediset_cloud/node_modules/@sap/cds/lib/srv/middlewares/ctx-model.js:9:21)
[CDS]     at /Users/shashwatjain/Repos/mymediset_cloud/node_modules/@cap-js-community/websocket/src/socket/base.js:237:16
[CDS]     at call (/Users/shashwatjain/Repos/mymediset_cloud/node_modules/@cap-js-community/websocket/src/socket/ws.js:295:9)
[CDS]     at /Users/shashwatjain/Repos/mymediset_cloud/node_modules/@cap-js-community/websocket/src/socket/ws.js:299:13
[CDS]     at wrapNext (/Users/shashwatjain/Repos/mymediset_cloud/node_modules/@cap-js-community/websocket/src/socket/base.js:233:13)
[CDS]     at basic_auth (/Users/shashwatjain/Repos/mymediset_cloud/node_modules/@sap/cds/lib/srv/middlewares/auth/basic-auth.js:26:5)
[CDS]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

After inspection i can see that req coming in from WS does not have a base url property:

module.exports = ()=> {

  const cds = require ('../../index'), LOG = cds.log()
  const context_model_required = cds.requires.extensibility || cds.requires.toggles
  if (!context_model_required) return []

  const { model4 } = require('../srv-models')
  return async function cds_context_model (req,res, next) {
    if (req.baseUrl.startsWith('/-/')) return next() //> our own tech services cannot be extended ///<<<<<FAILS HERE
    const ctx = cds.context
    if (ctx.tenant || ctx.features?.given) try {
      ctx.model = req.__model = await model4 (ctx.tenant, ctx.features) // REVISIT: req.__model is because of Okra
    } catch (e) {
      LOG.error(e)
      return res.status(503) .json ({ // REVISIT: we should throw a simple error, nothing else! -> this is overly OData-specific!
        error: { code: '503', message:
          process.env.NODE_ENV === 'production' ? 'Service Unavailable' :
          'Unable to get context-specific model due to: ' + e.message
        }
      })
    }
    next()
  }

}

Toggles is turned on in the project.

@oklemenz2
Copy link
Contributor

Thanks for reporting this bug. I will fix this in next release that will be available next week...

@oklemenz2 oklemenz2 self-assigned this Jan 26, 2025
@oklemenz2 oklemenz2 added the bug Something isn't working label Jan 26, 2025
@oklemenz2
Copy link
Contributor

I provided a fix 5cdadcb.
It will be included in release next week Monday...

@oklemenz2
Copy link
Contributor

Version 1.6.0 is available that should fix this issue.
https://github.com/cap-js-community/websocket/releases/tag/v1.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants