├── .firebaserc ├── functions ├── src │ ├── modules │ │ └── app.module.ts │ └── server.ts ├── tsconfig.json ├── webpack.config.js └── package.json ├── firebase.json ├── README.md ├── .gitignore └── public ├── 404.html └── _index.html /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /functions/src/modules/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | 3 | @Module({}) 4 | export class ApplicationModule {} -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "hosting": { 3 | "public": "public", 4 | "rewrites": [{ 5 | "source": "**", 6 | "function": "api" 7 | }], 8 | "ignore": [ 9 | "firebase.json", 10 | "**/.*", 11 | "**/node_modules/**" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /functions/src/server.ts: -------------------------------------------------------------------------------- 1 | import * as functions from 'firebase-functions'; 2 | import * as express from 'express'; 3 | import { Express } from 'express'; 4 | 5 | import { NestFactory } from '@nestjs/core'; 6 | import { ApplicationModule } from './modules/app.module'; 7 | 8 | const server: Express = express(); 9 | 10 | const startNestApplication = async (expressInstance: Express) => { 11 | const app = await NestFactory.create(ApplicationModule, expressInstance); 12 | app.init(); 13 | } 14 | 15 | startNestApplication(server); 16 | exports.api = functions.https.onRequest(server); -------------------------------------------------------------------------------- /functions/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["es6", "es2015.promise"], 4 | "module": "commonjs", 5 | "noImplicitAny": false, 6 | "outDir": "", 7 | "sourceMap": true, 8 | "removeComments": true, 9 | "noLib": false, 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "allowJs": true, 13 | "target": "es6", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ] 17 | }, 18 | "include": [ 19 | "src/**/*.ts", 20 | "spec/**/*.ts" 21 | ], 22 | "exclude": [ 23 | "node_modules", 24 | "**/*.spec.ts" 25 | ] 26 | } -------------------------------------------------------------------------------- /functions/webpack.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const nodeExternals = require('webpack-node-externals'); 4 | 5 | module.exports = { 6 | entry: './src/server.ts', 7 | output: { 8 | filename: 'index.js', // <-- Important 9 | libraryTarget: 'this' // <-- Important 10 | }, 11 | target: 'node', // <-- Important 12 | module: { 13 | rules: [ 14 | { 15 | test: /\.tsx?$/, 16 | loader: 'ts-loader', 17 | options: { 18 | transpileOnly: true 19 | } 20 | } 21 | ] 22 | }, 23 | resolve: { 24 | extensions: [ '.ts', '.tsx', '.js' ] 25 | }, 26 | externals: [nodeExternals()] // <-- Important 27 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Nest](http://gdurl.com/lEeN) 2 | 3 | This is a starter repository for who wants to start a Nest API project and host it with Firebase Cloud Functions. 4 | 5 | ### Prerequisites 6 | 7 | First of all, you need to set the Firebase project inside .firebaserc, to do so just replace \. Then, you need the following tools installed globally. 8 | 9 | * [Firebase tools](https://firebase.google.com/docs/cli/?hl=pt-br) 10 | * [Webpack](https://webpack.js.org/) 11 | * [Nodemon](https://www.npmjs.com/package/nodemon/tutorial) 12 | 13 | ### How it works 14 | 15 | * To build the app `$ npm run build` 16 | * To run the server `$ npm run serve` 17 | * To run the server for development `$ npm run serve:dev` 18 | * To deploy it to Firebase `$ npm run deploy` 19 | 20 | ### Problems 21 | 22 | If you have problemas, read this [artlice](https://dev.to/caiorcferreira/hosting-an-api-in-firebase-writen-with-typescript-and-nest) about making this repository, which have some troubleshooting tips. -------------------------------------------------------------------------------- /functions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nestjs-firebase", 3 | "description": "NestJS app with Cloud Functions for Firebase", 4 | "scripts": { 5 | "build": "webpack", 6 | "serve": "webpack && firebase serve --only functions,hosting", 7 | "serve:dev": "nodemon -e ts --exec npm run serve", 8 | "deploy": "webpack && firebase deploy --only functions,hosting" 9 | }, 10 | "dependencies": { 11 | "firebase-admin": "~4.2.1", 12 | "firebase-functions": "^0.5.9", 13 | "@nestjs/common": "*", 14 | "@nestjs/core": "*", 15 | "@nestjs/microservices": "*", 16 | "@nestjs/testing": "*", 17 | "@nestjs/websockets": "*", 18 | "@types/express": "^4.0.37", 19 | "express": "^4.15.4", 20 | "redis": "^2.7.1", 21 | "reflect-metadata": "^0.1.10", 22 | "rxjs": "^5.0.3", 23 | "typescript": "^2.3.2" 24 | }, 25 | "devDependencies": { 26 | "@types/node": "^7.0.5", 27 | "ts-loader": "^2.3.3", 28 | "webpack-node-externals": "^1.6.0" 29 | }, 30 | "private": true 31 | } 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/node 3 | 4 | ### Node ### 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | 24 | # nyc test coverage 25 | .nyc_output 26 | 27 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 28 | .grunt 29 | 30 | # Bower dependency directory (https://bower.io/) 31 | bower_components 32 | 33 | # node-waf configuration 34 | .lock-wscript 35 | 36 | # Compiled binary addons (http://nodejs.org/api/addons.html) 37 | build/Release 38 | 39 | # Dependency directories 40 | node_modules/ 41 | **/node_modules/** 42 | jspm_packages/ 43 | 44 | # Typescript v1 declaration files 45 | typings/ 46 | 47 | # Optional npm cache directory 48 | .npm 49 | 50 | # Optional eslint cache 51 | .eslintcache 52 | 53 | # Optional REPL history 54 | .node_repl_history 55 | 56 | # Output of 'npm pack' 57 | *.tgz 58 | 59 | # Yarn Integrity file 60 | .yarn-integrity 61 | 62 | # dotenv environment variables file 63 | .env 64 | 65 | 66 | # End of https://www.gitignore.io/api/node 67 | 68 | assets/ 69 | functions/index.js 70 | -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Page Not Found 7 | 8 | 23 | 24 | 25 |
26 |

404

27 |

Page Not Found

28 |

The specified file was not found on this website. Please check the URL for mistakes and try again.

29 |

Why am I seeing this?

30 |

This page was generated by the Firebase Command-Line Interface. To modify it, edit the 404.html file in your project's configured public directory.

31 |
32 | 33 | 34 | -------------------------------------------------------------------------------- /public/_index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Welcome to Firebase Hosting 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 32 | 33 | 34 |
35 |

Welcome

36 |

Firebase Hosting Setup Complete

37 |

You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary!

38 | Open Hosting Documentation 39 |
40 |

Firebase SDK Loading…

41 | 42 | 64 | 65 | 66 | --------------------------------------------------------------------------------