Skip to content

Commit 9e47ca5

Browse files
Resul AvanResul Avan
Resul Avan
authored and
Resul Avan
committed
periodic warming up function
1 parent a8f9c8f commit 9e47ca5

File tree

7 files changed

+28
-9
lines changed

7 files changed

+28
-9
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ lib
106106
**/*.tgz
107107

108108
# firebase
109-
functions/nuxt.config.ts
110109
public
111110
firebase-admin-credentials.json
112111
firebase-messaging-sw.js
112+
113113
package-lock.json
114114

115115
tmp

functions/modules/handlers-module/src/handler-config.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import admin from 'firebase-admin'
33
export class HandlerConfig {
44

55
private static credentials = ''
6+
private static websiteUrl = 'https://nuxt-ts-firebase-auth-ssr.web.app/'
67

78
private static readonly defaultInitializer = () => {
89
admin.initializeApp({
@@ -21,10 +22,18 @@ export class HandlerConfig {
2122
console.log('firebase admin is initialized by custom credentials')
2223
}
2324

24-
static setCredentials = (credentials: string) => {
25+
static setCredentials (credentials: string) {
2526
HandlerConfig.credentials = credentials
2627
}
2728

29+
static setWebSiteUrl (websiteUrl: string) {
30+
HandlerConfig.websiteUrl = websiteUrl
31+
}
32+
33+
static getWebsiteUrl () {
34+
return HandlerConfig.websiteUrl
35+
}
36+
2837
static getAdmin () {
2938
if (admin.apps.length === 0) {
3039
this.credentials ? this.credentialsInitializer() : this.defaultInitializer()

functions/modules/handlers-module/src/sitemap-handler.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Request, RequestHandler, Response } from 'express'
22
import { SitemapStream, streamToPromise } from 'sitemap'
33
import { createGzip } from 'zlib'
44
import { handleGenericError } from './service/request-handler-service'
5+
import { HandlerConfig } from './handler-config'
56

67
const staticRoutes = [
78
'/',
@@ -27,7 +28,7 @@ export const sitemapHandler: RequestHandler = async (req: Request, res: Response
2728

2829
await Promise.resolve()
2930
.then(() => {
30-
const smStream = new SitemapStream({ hostname: 'https://nuxt-ts-firebase-auth-ssr.web.app/' })
31+
const smStream = new SitemapStream({ hostname: HandlerConfig.getWebsiteUrl() })
3132
const pipeline = smStream.pipe(createGzip())
3233

3334
staticRoutes.forEach((route) =>

functions/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"rxjs": "^6.6.0",
4646
"sitemap": "^6.2.0",
4747
"slug": "^3.3.2",
48+
"sync-request": "^6.1.0",
4849
"types-module": "file:modules/types-module",
4950
"uuid": "^8.3.0",
5051
"vee-validate": "^3.3.7",

functions/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { nuxtOnFunction } from './nuxtOnFunction'
22
export { apiApp } from './apiApp'
33
export { sitemapApp } from './sitemapApp'
4+
export { warmUpScheduledFunction } from './warmUpScheduledFunction'
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { pubsub } from "firebase-functions"
2+
import syncRequest from 'sync-request'
3+
import { HandlerConfig } from 'handlers-module'
4+
import { ApiConfig } from 'types-module'
5+
6+
export const warmUpScheduledFunction = pubsub
7+
.schedule('0 * * * *')
8+
.onRun((context) => {
9+
syncRequest('GET', HandlerConfig.getWebsiteUrl())
10+
syncRequest('GET', `${HandlerConfig.getWebsiteUrl()}${ApiConfig.healthy}`)
11+
syncRequest('GET', `${HandlerConfig.getWebsiteUrl()}/sitemap.xml`)
12+
})

src/components/modal/SetEmailPasswordModal.vue

+1-6
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@
4141
<script lang="ts">
4242
import { Component, Prop, Vue } from 'nuxt-property-decorator'
4343
import { AuthUser, ProviderType } from 'types-module'
44-
import {
45-
LoginCredentials,
46-
NotificationMessage,
47-
ProviderConfig,
48-
StateNamespace
49-
} from '../../types'
44+
import { LoginCredentials, NotificationMessage, ProviderConfig, StateNamespace } from '../../types'
5045
import SocialLogin from '~/components/form/SocialLogin.vue'
5146
import SetEmailPasswordForm from '~/components/form/SetEmailPasswordForm.vue'
5247
import LoginForm from '~/components/form/LoginForm.vue'

0 commit comments

Comments
 (0)