diff --git a/example/js/exampleApiServer.js b/example/js/exampleApiServer.js index aa9a74e..db4bff9 100644 --- a/example/js/exampleApiServer.js +++ b/example/js/exampleApiServer.js @@ -31,10 +31,11 @@ function parseBoolean(value) { return undefined; } -export function createApp(service) { +export function createApp(service, middleware) { const app = express(); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); + middleware.forEach(func => app.use(func)); /** Gets widgets. */ app.get('/widgets', function (req, res, next) { diff --git a/example/ts/src/exampleApiServer.ts b/example/ts/src/exampleApiServer.ts index e9ba19d..912e2e5 100644 --- a/example/ts/src/exampleApiServer.ts +++ b/example/ts/src/exampleApiServer.ts @@ -32,10 +32,11 @@ function parseBoolean(value: string | undefined) { return undefined; } -export function createApp(service: IExampleApi): express.Application { +export function createApp(service: IExampleApi, middleware: ((...args: any[]) => void)[]): express.Application { const app = express(); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); + middleware.forEach(func => app.use(func)); /** Gets widgets. */ app.get('/widgets', function (req, res, next) { diff --git a/src/Facility.CodeGen.JavaScript/JavaScriptGenerator.cs b/src/Facility.CodeGen.JavaScript/JavaScriptGenerator.cs index a2f2d04..65ada04 100644 --- a/src/Facility.CodeGen.JavaScript/JavaScriptGenerator.cs +++ b/src/Facility.CodeGen.JavaScript/JavaScriptGenerator.cs @@ -338,11 +338,12 @@ protected override CodeGenOutput GenerateOutputCore(ServiceInfo service) } code.WriteLine(); - using (code.Block("export function createApp(service" + IfTypeScript($": I{capModuleName}") + ")" + IfTypeScript(": express.Application") + " {", "}")) + using (code.Block("export function createApp(service" + IfTypeScript($": I{capModuleName}") + ", middleware" + IfTypeScript(": ((...args: any[]) => void)[]") + ")" + IfTypeScript(": express.Application") + " {", "}")) { code.WriteLine("const app = express();"); code.WriteLine("app.use(bodyParser.json());"); code.WriteLine("app.use(bodyParser.urlencoded({ extended: true }));"); + code.WriteLine("middleware.forEach(func => app.use(func));"); foreach (var httpMethodInfo in httpServiceInfo.Methods) {