Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

325
Views
Export Fastify server as firebase cloud functions

I want to export Fastify server to firebase cloud functions (so I can run them through emulators), Following is my code:

import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import {
  FastifyAdapter,
  NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
import * as functions from 'firebase-functions';
const http = require('http')
const Fastify = require('fastify')

let handleRequest = null

const serverFactory = (handler, opts) => {
  handleRequest = handler
  return http.createServer()
}

const fastify = Fastify({serverFactory,});

export const createFastifyServer = async (fastifyInstance) => {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter()
  );

  app.useGlobalPipes(new ValidationPipe());

  await app.init()
}
createFastifyServer(fastify)
  .then(() => console.log('Nest Ready'))
  .catch((err) => console.error('Nest broken', err));

exports.app = functions.https.onRequest((req, res) => {
    fastify.ready((err) => {
      if (err) throw err
        handleRequest(req, res)
    })
})

And when I try to access the exported functions from the path, e.g. http://localhost:port/firebase project/regionapp/app after running the local emulators then I get route not found exception e.g. {"message":"Route GET:/ not found","error":"Not Found","statusCode":404}.

I'm aware of using get/post with fastify directly e.g.

fastify.get('/', (req, reply) => {
  console.log('Hello World')
  reply.send({ hello: 'world' })
}) 

but want to export my already created express server app (created through NestFastifyApplication) as fastify, in express we simply do export const api: functions.HttpsFunction = firebase.https.onRequest(express_server); but what is the alternate for fastify? Thanks.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!