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

Global middleware without separate express server #25

Open
szymarcus opened this issue Feb 17, 2023 · 0 comments
Open

Global middleware without separate express server #25

szymarcus opened this issue Feb 17, 2023 · 0 comments

Comments

@szymarcus
Copy link

Hi this is more of a question than an issue. I have the below project setup and want to create a global middleware. Since we are not using the express server separately as suggested here but rather through the cds runtime I have no idea how to register a middleware globally. Help would be really appreciated. Does anyone have an idea on this?

Thanks a lot in advance.

import 'reflect-metadata';
import { Application } from 'express';
import { useContainer } from 'cds-routing-handlers';
import Container from 'typedi';
import { runJobs } from '../src/common/cron-service/cron-service.internal';
import { isDevelopmentEnv, log, populateLocalUserScopes } from '../src/utils';

useContainer(Container);

//eslint-disable-next-line
const proxy = require('@sap/cds-odata-v2-adapter-proxy');
//eslint-disable-next-line
const cds = require('@sap/cds');

cds.on('bootstrap', (app: Application) => {
  process.env.CDS_ASSERT_FORMAT_FLAGS = 'i'; // this flag has default value of 'u' - unicode, therefore making the regex compilation fail
  app.use(proxy());
});
cds.once('listening', () => {
  log.info('Scheduling cron jobs...');
  runJobs();
});

if (isDevelopmentEnv()) {
  populateLocalUserScopes();
}

module.exports = cds.server;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant