Skip to content

Commit

Permalink
fix(web): wrong api url
Browse files Browse the repository at this point in the history
  • Loading branch information
yamcodes committed Mar 30, 2024
1 parent ebe804b commit 577d4e8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
6 changes: 4 additions & 2 deletions apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import { onRequest } from 'firebase-functions/v2/https';
import { fastify } from 'fastify';
import * as logger from 'firebase-functions/logger';
import { registerRoutes, setContentTypeParser } from './utils';

const app = fastify({
Expand All @@ -45,7 +46,8 @@ setContentTypeParser(

registerRoutes(app);

export const server = onRequest(async (request, reply) => {
export const server = onRequest(async (request, response) => {
await app.ready();
app.server.emit('request', request, reply);
logger.info('Hello logs!', { structuredData: true });
app.server.emit('request', request, response);
});
23 changes: 16 additions & 7 deletions apps/api/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ export const setContentTypeParser = (

export const registerRoutes = (fastify: FastifyInstance) => {
// define your endpoints here...
fastify.post('/some-route-here', (_request) => {
return { message: 'Hello World!!' };
});
// fastify.post('/some-route-here', (_request) => {
// return { message: 'Hello World!!' };
// });

fastify.get('/', async (request, reply) => {
void reply.send({ message: 'Hello World!!' });
});
// fastify.get('/', async (request, reply) => {
// void reply.send({ message: 'Hello World!!' });
// });

// fastify.get('/legacy', (_req, res) => {
// void res.send({
// hello: 'world',
// randomName: faker.person.firstName(),
// iLikeTurtles: iLikeTurtles(),
// nice: 69,
// });
// });

fastify.get('/legacy', (_req, res) => {
fastify.get('*', (_req, res) => {
void res.send({
hello: 'world',
randomName: faker.person.firstName(),
Expand Down
8 changes: 5 additions & 3 deletions apps/web/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ export const App = () => {
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
<div style={{ textAlign: 'left' }}>
<p style={{ fontWeight: 'bold' }}>From packages/utilities</p>
<p style={{ fontWeight: 'bold' }}>
From packages/utilities (utilities)
</p>
<pre>{JSON.stringify(iLikeTurtles())}</pre>
</div>
<div style={{ textAlign: 'left' }}>
<p style={{ fontWeight: 'bold' }}>Source code</p>
<a
style={{ color: 'lightblue' }}
href="https://github.com/yamcodes/turborepo-firebase-example"
href="https://github.com/yamcodes/turborepo-firebase-starter/tree/main/apps/web"
>
https://github.com/yamcodes/turborepo-firebase-example
https://github.com/yamcodes/turborepo-firebase-starter/tree/main/apps/web
</a>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
"rewrites": [
{
"source": "/api/**",
"function": "server"
"function": {
"functionId": "server",
"region": "us-central1",
"pinTag": true
}
},
{
"source": "**",
Expand Down

0 comments on commit 577d4e8

Please sign in to comment.