Slide 22
Slide 22 text
import { Response, Request } from 'express'
import * as bodyParser from 'body-parser'
import { GoogleAuth } from 'google-auth-library'
const { BASE_URL, TARGET_AUDIENCE } = process.env
const gAuth = new GoogleAuth()
const app = require('express')()
app.use(bodyParser.json())
app.all('/', async (req: Request, res: Response) => {
const client = await gAuth.getIdTokenClient(TARGET_AUDIENCE)
client.request({
baseURL: BASE_URL || 'https://example.an.r.appspot.com/',
url: `test/url`
})
.then((responseData) => {
res.json(responseData.data)
})
.catch((err) => {
res.status(err.response?.status ?? 400)
res.json({})
})
})
module.exports = app
~/api/index.ts