Skip to content

Commit

Permalink
fix: non-http azure functions in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed Jan 22, 2024
1 parent e0675d5 commit 70630da
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
9 changes: 7 additions & 2 deletions packages/azure-functions/src/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ export class AzureFunctionsTrigger extends BaseFunctionTrigger {
timer(funcName: string, option: Omit<TimerFunctionOptions, 'handler'>) {
return new AzureFunctionsHandler<Timer, unknown | void>(
funcName,
this.parseFunctionOption(funcName, option),
this.parseFunctionOption(funcName, {
...option,
endpointOption: {
type: 'timer',
},
}),
funcOption => {
app.timer(funcName, {
...option,
Expand All @@ -100,7 +105,7 @@ export class AzureFunctionsTrigger extends BaseFunctionTrigger {
endpointOption: {
...opt?.endpointOption,
route: (opt?.endpointOption as HttpEndpointOption)?.route ?? funcName,
type: (opt?.endpointOption as HttpEndpointOption)?.type ?? 'http',
type: opt?.endpointOption?.type ?? 'generic',
},
extraInputs: opt?.extraInputs ?? [],
extraOutputs: opt?.extraOutputs ?? [],
Expand Down
11 changes: 4 additions & 7 deletions packages/azure-functions/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AfterServerStartedMetadata, NammathamApp } from '@nammatham/core';

import { gray, yellow } from 'colorette';
import { trimSlash } from '@nammatham/core';
import { logger, trimSlash } from '@nammatham/core';

import type { AzureFunctionsEndpoint } from './types';

Expand Down Expand Up @@ -34,7 +34,6 @@ export async function printRegisteredFunctions(
const methods = `[${getMethods(func).join(',')}]`;
console.log(` - ${func.name} ${gray(methods)} ${gray(getFullUrl(func, option.port))}`);
}
console.log('');
return azureFunctions;
}

Expand All @@ -49,12 +48,10 @@ export async function printRegisteredNonHttpFunctions(
.filter(func => func.type === 'azure-functions')
.filter(func => func.endpointOption?.type !== 'http') as AzureFunctionsEndpoint<unknown, unknown>[];
if (azureFunctions.length === 0) return [];
console.log(`${yellow(`----------------------------------------------`)}\n`);
console.log(`\n${yellow('Non-HTTP Functions (In Develpment Mode Only):')}\n`);
console.log(`\n${yellow('Non-HTTP Functions, accessed by HTTP (dev mode):')}\n`);
for (const func of azureFunctions) {
const methods = `[${getMethods(func).join(',')}]`;
console.log(` - ${func.name} ${gray(methods)} ${gray(getFullUrl(func, option.port))}`);
const type = `[${func.endpointOption?.type ?? 'generic'}]`;
console.log(` - ${func.name} ${gray(type)} ${gray(getFullUrl(func, option.port))}`);
}
console.log('');
return azureFunctions;
}
4 changes: 3 additions & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export interface GenericEndpointOption extends EndpointOptionBase, Record<string
type: 'generic';
}

export type EndpointOption = HttpEndpointOption | GenericEndpointOption;
export type UnknownEndpointOption = EndpointOptionBase & Record<string, unknown>;

export type EndpointOption = HttpEndpointOption | GenericEndpointOption | UnknownEndpointOption;

export type WithEndpointOption = { endpointOption?: EndpointOption };

Expand Down
4 changes: 2 additions & 2 deletions packages/express/src/express-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export function startExpress(
const endTime = performance.now();
const durationMs = Math.floor(endTime - app.startTime);
logger.debug(`Server started at http://localhost:${port}`);
console.log(`${await logo()} ${gray(`ready in ${durationMs}ms`)}\n`);
console.log(`${await logo()} ${gray(`ready in ${durationMs} ms`)}\n`);
console.log(`\n${blue('Express server started')}\n`);
console.log(` ┃ Local ${greenBright(`http://localhost:${port}`)}`);
console.log(` ┃ Host ${gray('Not Available')} \n`);

await handlerResolver.afterServerStarted(app, { port, allowAllFunctionsAccessByHttp });
// console.log(`\nServer Ready \n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n`);
console.log('\n');
});
}

0 comments on commit 70630da

Please sign in to comment.