1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21import functions from '@google-cloud/functions-framework'
functions.http('ping', (req, res) => {
// Set CORS headers
res.set('Access-Control-Allow-Origin', '*')
res.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
res.set(
'Access-Control-Allow-Headers',
'Content-Type, Authorization, Accept'
)
// Handle preflight requests
if (req.method === 'OPTIONS') {
res.status(200).send('')
return
}
// Your original logic
res.send(`Hello ${req.query.name || req.body.name || 'World'}!`)
})