Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Update dependencies and applications #18

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ firebase-debug.log

public/admin/firebaseConfig.js
\.firebase/


**/.env.local
**/*.log
9 changes: 4 additions & 5 deletions firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
]
},
{
"source":
"**/*.@(jpg|jpeg|gif|png|svg|js|css|eot|otf|ttf|ttc|woff|font.css)",
"source": "**/*.@(jpg|jpeg|gif|png|svg|js|css|eot|otf|ttf|ttc|woff|font.css)",
"headers": [
{
"key": "Cache-Control",
Expand All @@ -38,9 +37,9 @@
],
"redirects": [
{
"source" : "/",
"destination" : "https://techheaven.org",
"type" : 301
"source": "/",
"destination": "https://techheaven.org",
"type": 301
}
]
}
Expand Down
2 changes: 2 additions & 0 deletions functions/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
lib
14 changes: 14 additions & 0 deletions functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: [
"@typescript-eslint"
],
extends: [
"plugin:@typescript-eslint/recommended"
],
rules:{
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/explicit-boundary-types": "off"
}
}
1 change: 1 addition & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.local
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated with .gitignote rules at root folder.

31 changes: 19 additions & 12 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,37 @@
"name": "functions",
"description": "TypeScript sample Cloud Functions for Firebase",
"dependencies": {
"@types/body-parser": "^1.16.8",
"@types/cookie-parser": "^1.4.1",
"@types/cors": "^2.8.3",
"body-parser": "^1.18.2",
"@types/body-parser": "^1.19.2",
"@types/cookie-parser": "^1.4.2",
"@types/cors": "^2.8.12",
"body-parser": "^1.19.1",
"cookie-parser": "latest",
"cors": "latest",
"express": "^4.16.2",
"express-validator": "^5.0.1",
"firebase-admin": "~5.5.0",
"firebase-functions": "^0.8.1"
"dotenv": "^16.0.0",
"express": "^4.17.2",
"express-validator": "^6.14.0",
"firebase-admin": "~10.0.2",
"firebase-functions": "^3.16.0"
},
"devDependencies": {
"@types/express": "^4.0.37",
"tslint": "^5.8.0",
"typescript": "^2.6.1"
"@types/express": "^4.17.13",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"eslint": "^8.8.0",
"typescript": "^4.5.5"
},
"scripts": {
"build": "./node_modules/.bin/tslint -p tslint.json && ./node_modules/.bin/tsc",
"lint": "eslint --fix --ext .ts,.js .",
"build": "yarn lint && tsc",
"serve": "yarn run build && firebase serve --only functions",
"shell": "yarn run build && firebase experimental:functions:shell",
"start": "yarn run shell",
"deploy": "yarn run build && firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"engines": {
"node": "16"
},
"private": true
}
6 changes: 3 additions & 3 deletions functions/src/RedirectHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as admin from "firebase-admin";
import * as express from "express";
import admin from "firebase-admin";
import express from "express";

class RedirectHandler {

Expand Down Expand Up @@ -68,4 +68,4 @@ class RedirectHandler {

}

export default RedirectHandler
export default RedirectHandler
8 changes: 4 additions & 4 deletions functions/src/api/Api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as express from 'express'
import express from 'express'
import ManagementApi from "./management/ManagementApi";
import authorizeRequest from "./auth/FirebaseAuth";
import {respondFailure} from "./util/ApiResponse";
import * as bodyParser from "body-parser";
import * as cors from "cors";
import bodyParser from "body-parser";
import cors from "cors";

class Api {

Expand Down Expand Up @@ -45,4 +45,4 @@ class Api {

const ApiInstance = new Api();

export default ApiInstance
export default ApiInstance
4 changes: 2 additions & 2 deletions functions/src/api/Endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as express from 'express'
import express from 'express'

interface Endpoint {
register(router: express.Router)
}

export default Endpoint
export default Endpoint
4 changes: 2 additions & 2 deletions functions/src/api/EndpointGroup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as express from "express";
import express from "express";

interface EndpointGroup {
setup(): express.Router
}

export default EndpointGroup
export default EndpointGroup
4 changes: 2 additions & 2 deletions functions/src/api/auth/FirebaseAuth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as admin from 'firebase-admin'
import admin from 'firebase-admin'
import {respondFailure} from "../util/ApiResponse";

function checkIsAdmin(uid: string) {
Expand Down Expand Up @@ -49,4 +49,4 @@ const authorizeRequest = (req, res, next) => {
});
};

export default authorizeRequest
export default authorizeRequest
4 changes: 2 additions & 2 deletions functions/src/api/management/ManagementApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as express from 'express'
import express from 'express'
import EndpointGroup from "../EndpointGroup";
import UrlEndpoint from "./UrlEndpoint";

Expand All @@ -17,4 +17,4 @@ class ManagementApi implements EndpointGroup {

const instance = new ManagementApi();

export default instance
export default instance
10 changes: 5 additions & 5 deletions functions/src/api/management/UrlEndpoint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Endpoint from "../Endpoint";
import * as express from 'express'
import {checkSchema, validationResult} from "express-validator/check";
import * as admin from "firebase-admin";
import express from 'express'
import {checkSchema, validationResult} from "express-validator";
import admin from "firebase-admin";
import {respondFailure, respondWith} from "../util/ApiResponse";

class UrlEndpoint implements Endpoint {
Expand Down Expand Up @@ -124,10 +124,10 @@ class UrlEndpoint implements Endpoint {
})
}

private handleGetRequest(req: express.Request, res: express.Response) {
private handleGetRequest(_req: express.Request, _res: express.Response) {
// todo
}

}

export default UrlEndpoint
export default UrlEndpoint
8 changes: 4 additions & 4 deletions functions/src/api/util/ApiResponse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as express from 'express'
import express from 'express'

function respondWith(res: express.Response, body: any) {
function respondWith(res: express.Response, body: unknown) {
res.status(200);
res.set('content-type', 'application/json');
if (body !== undefined && body !== null) {
Expand All @@ -10,7 +10,7 @@ function respondWith(res: express.Response, body: any) {
}
}

function respondFailure(res: express.Response, status: number, message: string, errors: any = null) {
function respondFailure(res: express.Response, status: number, message: string, errors: unknown = null) {
res.status(status);
res.json({
status: status,
Expand All @@ -19,4 +19,4 @@ function respondFailure(res: express.Response, status: number, message: string,
});
}

export {respondWith, respondFailure}
export {respondWith, respondFailure}
15 changes: 8 additions & 7 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';

import * as functions from 'firebase-functions'
import * as express from 'express'
import * as admin from 'firebase-admin'
import express from 'express'
import admin from 'firebase-admin'
import RedirectHandler from "./RedirectHandler";
import Api from "./api/Api";
import * as cookieParser from "cookie-parser";
import cookieParser from "cookie-parser";
import dotenv from "dotenv"

dotenv.config()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you have any .env config required for production? Pls, put here any sample file and add installation instructions to README.md file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's whole unnecessary, because Firebase is using dotfile internally: https://firebase.google.com/docs/functions/config-env#env-variables


// Initialize Firebase App
admin.initializeApp(functions.config().firebase);
admin.initializeApp();

// Routing
const app = express();
Expand All @@ -29,4 +30,4 @@ app.all("*", ((req, res) => {
res.status(500);
}));

export const redirect = functions.https.onRequest(app);
exports.redirect = functions.https.onRequest(app);
13 changes: 11 additions & 2 deletions functions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{
"compilerOptions": {
"lib": ["es6"],
"lib": ["es6", "es2018", "es2017", "es2016"],
"module": "commonjs",
"noImplicitReturns": true,
"outDir": "lib",
"sourceMap": true,
"target": "es6"
"target": "es6",
"alwaysStrict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"checkJs": false
},
"compileOnSave": true,
"include": [
"src"
],
"exclude": [
"node_modules"
]

}
Loading