Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion example/js/exampleApiServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion example/ts/src/exampleApiServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/Facility.CodeGen.JavaScript/JavaScriptGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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") + " {", "}"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

middleware should be optional.

{
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));");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test if middleware is truthy.


foreach (var httpMethodInfo in httpServiceInfo.Methods)
{
Expand Down