Skip to content

Commit

Permalink
fix(example): fix node example
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed May 15, 2024
1 parent b12bd78 commit f748da2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion examples/with-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"license": "MIT",
"dependencies": {
"@hono/node-server": "^1.8.1",
"hono": "^4.3.2",
"hono": "^4.3.6",
"nammatham": "workspace:*"
},
"devDependencies": {
Expand Down
43 changes: 29 additions & 14 deletions examples/with-node/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import { Hono } from 'hono';
import { serve } from '@hono/node-server';
import { initNammatham, register } from 'nammatham';
import { logger } from 'hono/logger';

const app = new Hono().basePath('/api');
// DO NOT SET `basePath` for Hono App, Azure Functions will handle it
const app = new Hono();
app.use(logger());

app.get('/SimpleHttpTrigger', c => {
const userAgent = c.req.header('user-agent');
console.log(`user agent is: ${userAgent}`);
const func = initNammatham();

const invocationId = c.req.header('x-azure-functions-invocationid');
console.log(`invocationid is: ${invocationId}`);
app.all(
...func.http({
route: '/SimpleHttpTrigger',
}),
c => {
// Getting the function context
const context = c.var.context;

return c.text('Hello World from node.js worker');
});
context.log('JavaScript HTTP trigger function processed a request.');
context.log(`invocationid is: ${context.invocationId}`);
context.log(`The third log message.`);

return context.json({
hello: 'world',
});
}
);

export default serve(
register({
fetch: app.fetch,
func,
})
);

const port = parseInt(process.env.FUNCTIONS_CUSTOMHANDLER_PORT || '4000');
console.log(`Start server on on http://localhost:${port}`);

serve({
fetch: app.fetch,
port,
});
9 changes: 2 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f748da2

Please sign in to comment.