本文整理匯總了TypeScript中firebase-functions.config函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript config函數的具體用法?TypeScript config怎麽用?TypeScript config使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了config函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
.https.onCall(async (data) => {
const transporter = nodemailer.createTransport({
host: 'mail.sfwinterbach.com',
port: 465,
secure: true,
auth: {
user: functions.config().mailer.email,
pass: functions.config().mailer.password
}
});
const fromName = 'Kontakt';
const fromEmail = 'kontaktformular@sfwinterbach.com';
const to = data.to;
const text = data.text;
const mailOptions = {
from: fromName + ' <' + fromEmail + '>',
to: to,
subject: 'Anfrage auf ' + transporter.host,
text: text,
html: text,
};
const info = await transporter.sendMail(mailOptions);
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
console.log(info);
return info;
});
示例2: sendEmail
static sendEmail(mailOptions) {
const email = encodeURIComponent(functions.config().smtp.email);
const password = encodeURIComponent(functions.config().smtp.password);
const mailTransport = nodemailer.createTransport(
`smtps://${email}:${password}@authsmtp.uchicago.edu`,
);
return new Promise(resolve => mailTransport.sendMail(mailOptions, resolve));
}
示例3: Promise
return new Promise((resolve, reject) =>{
let id, key;
try{
id = functions.config().mailjet.id;
key = functions.config().mailjet.key;
}catch(e){
id = process.env.mailjetid;
key = process.env.mailjetkey;
}
mailjet.connect(id, key)
.post("send", {'version': 'v3.1'})
.request(requestBody)
.then((result) => {
console.log(result.body);
resolve(result.body);
})
.catch((err) => {
console.log(err);
reject(err);
});
});
示例4: env
export function env(key: string, fallback?: any, envPath?: string) {
dotenv.config({ path: envPath ? path.resolve(process.cwd(), envPath) : path.resolve(process.cwd(), '..', '.env') });
let response: any = false;
try {
response = resolve(functions.config(), key.toLowerCase().replace(/_/g, '.'));
if (!response) {
response = process.env[key];
}
} catch (error) {
response = process.env[key];
}
return response ? response : fallback;
};
示例5:
*
* For golden images uploaded to /goldens, read the data from images files and write the data to
* Firebase database under location /screenshot/goldens
* Screenshot tests can only read restricted database data with no credentials, and they cannot
* access.
* Google Cloud Storage. Therefore we copy the image data to database to make it available to
* screenshot tests.
*
* The JWT is stored in the data path, so every write to database needs a valid JWT to be copied to
* database/storage.
* All invalid data will be removed.
* The JWT has 3 parts: header, payload and signature. These three parts are joint by '/' in path.
*/
// Initialize the admin app
firebaseAdmin.initializeApp(firebaseFunctions.config().firebase);
/** The valid data types database accepts */
const dataTypes = ['result', 'sha', 'travis'];
/** The Json Web Token format. The token is stored in data path. */
const jwtFormat = '{jwtHeader}/{jwtPayload}/{jwtSignature}';
/** The temporary folder name for screenshot data that needs to be validated via JWT. */
const tempFolder = '/untrustedInbox';
/** Untrusted report data for a PR */
const reportPath = `${tempFolder}/screenshot/reports/{prNumber}/${jwtFormat}/`;
/** Untrusted image data for a PR */
const imagePath = `${tempFolder}/screenshot/images/{prNumber}/${jwtFormat}/`;
示例6: config
import {verify} from 'jsonwebtoken';
import {config} from 'firebase-functions';
/** The JWT secret. This is used to validate JWT. */
const jwtSecret = config().secret.jwt;
/** The repo slug. This is used to validate the JWT is sent from correct repo. */
const repoSlug = config().repo.slug;
export function verifyToken(token: string): boolean {
try {
// The returned value of the verify method can be either a string or a object. Reading
// properties without explicitly treating the result as `any` will lead to a TypeScript error.
const tokenPayload = verify(token, jwtSecret, {issuer: 'Travis CI, GmbH'}) as any;
if (tokenPayload.slug !== repoSlug) {
console.log(`JWT slugs are not matching. Expected ${repoSlug}`);
}
return true;
} catch (e) {
return false;
}
}
示例7: initializeApp
import { Agent } from 'https'
import axios from 'axios'
import { initializeApp, firestore } from 'firebase-admin'
import { config, https } from 'firebase-functions'
initializeApp(config().firebase)
const db = firestore()
const countRef = db.collection('irwtfy').doc('count')
const agent = new Agent({ keepAlive: true })
export const randomEntry = https.onRequest(async (request, response) => {
const doc = await countRef.get()
const data = doc.data()
let count: number
if (data && data.count && parseInt(data.count) % 1 === 0) {
count = parseInt(data.count)
} else {
const countResponse = await axios.get('https://www.blogger.com/feeds/6752139154038265086/posts/default', {
params: {
'alt': 'json',
'start-index': 1,
'max-results': 1,
},
httpsAgent: agent,
})
count = countResponse.data.feed.openSearch$totalResults.$t
await countRef.set({ count: count })
}
const resp = await axios.get('https://www.blogger.com/feeds/6752139154038265086/posts/default', {
示例8: require
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
const moment = require('moment');
import { birthdayWishes } from './birthday-wishes';
moment.locale('de');
// Sengrid
const sgMail = require('@sendgrid/mail');
const SENDGRID_API_KEY = functions.config().sendgrid.key;
sgMail.setApiKey(SENDGRID_API_KEY);
const db = admin.firestore();
const birthdayReminder = functions
.region('europe-west1')
.runWith({ memory: '512MB', timeoutSeconds: 12 }).pubsub
.schedule('0 5 * * *').onRun(async context => {
try {
const monthDay = moment().format('MM-DD');
const mailArray: any = [];
const recipients: {
email: string,
firstName: string,
lastName: string,
age: number
}[] = [];
示例9: require
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
const moment = require('moment');
const { google } = require('googleapis');
const GOOGLE_API_KEY = functions.config().google.calendar.key;
const getCalendar = google.calendar({ version: 'v3', auth: GOOGLE_API_KEY });
const db = admin.firestore();
const getGoogleCalendars = functions
.region('europe-west1')
.runWith({ memory: '1GB', timeoutSeconds: 25 })
.https.onRequest(async (req, res) => {
res.set('Access-Control-Allow-Origin', '*');
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow-Headers', 'Authorization, content-type');
res.header('Access-Control-Max-Age', '7200');
}
const timeMin = req.body.data && req.body.data.startDate ? req.body.data.startDate : moment().startOf('month').toISOString();
const timeMax = req.body.data && req.body.data.endDate ? req.body.data.endDate : moment().endOf('month').toISOString();
console.log(timeMin);
console.log(timeMax);
try {
const eventList: any[] = [];
示例10: express
import * as express from 'express';
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
import QuestionService from './service/QuestionServices';
import AnswerService from './service/AnswerServices';
admin.initializeApp(functions.config().firebase);
const app = express();
const questionService = new QuestionService();
const answerService = new AnswerService();
app.disable("x-powered-by");
app.post("/questions/create", async function CreateQuestion(req: express.Request, res: express.Response) {
questionService.Create(req.body.question, req.body.type, req.body.answers).then(resQuestion => {
res.status(200).send();
});
});
app.get("/questions/all", async function GetAllQuestions(req: express.Request, res: express.Response) {
questionService.GetAllQuestions().then(resQuestion => {
res.status(200).send(resQuestion);
});
});
app.get("/questions/:question", async function GetQuestion(req: express.Request, res: express.Response) {
questionService.GetQuestion(req.param('question')).then(resQeustion => {
res.status(200).send(resQeustion);
});
});