-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.js
More file actions
30 lines (27 loc) · 893 Bytes
/
Copy pathweather.js
File metadata and controls
30 lines (27 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { BigQuery } from '@google-cloud/bigquery';
export default async function handler(req, res) {
// These variables are set in the Vercel Dashboard under Environment Variables
const bigquery = new BigQuery({
projectId: process.env.GCP_PROJECT_ID,
credentials: {
client_email: process.env.GCP_CLIENT_EMAIL,
private_key: process.env.GCP_PRIVATE_KEY.replace(/\\n/g, '\n'),
},
});
const query = `
SELECT
city,
ROUND(avg_temp, 2) as avg_temp,
record_count
FROM \`${process.env.GCP_PROJECT_ID || 'routinematch-prod'}.city_intelligence.east_coast_city_summary\`
WHERE record_count > 0
ORDER BY avg_temp DESC
`;
try {
const [rows] = await bigquery.query({ query });
res.status(200).json(rows);
} catch (error) {
console.error('BigQuery Error:', error);
res.status(500).json({ error: error.message });
}
}