mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 13:45:24 +02:00
fix vercel load errors
This commit is contained in:
+14
-13
@@ -1,17 +1,15 @@
|
||||
import { applyCors, isAllowedOrigin } from './_cors.js';
|
||||
|
||||
const DROPBOX_APP_KEY = process.env.DROPBOX_APP_KEY;
|
||||
const DROPBOX_APP_SECRET = process.env.DROPBOX_APP_SECRET;
|
||||
const DROPBOX_REFRESH_TOKEN = process.env.DROPBOX_REFRESH_TOKEN;
|
||||
|
||||
const ALLOWED_ORIGIN = 'https://craze-data-check.vercel.app';
|
||||
const DROPBOX_SHARED_URL =
|
||||
process.env.DROPBOX_SHARED_URL ||
|
||||
process.env.DROPBOX_FILE_URL ||
|
||||
'https://www.dropbox.com/scl/fi/usa8me7ywgylrij2bt6hj/Data-Matrix.xlsx?rlkey=tsec8csrhye54u1fdvk15ped1&dl=1';
|
||||
|
||||
function setCors(req, res) {
|
||||
const origin = req.headers.origin;
|
||||
if (origin === ALLOWED_ORIGIN) {
|
||||
res.setHeader('Access-Control-Allow-Origin', ALLOWED_ORIGIN);
|
||||
}
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
||||
res.setHeader('Vary', 'Origin');
|
||||
applyCors(req, res, 'GET, OPTIONS');
|
||||
}
|
||||
|
||||
async function getAccessToken() {
|
||||
@@ -40,7 +38,7 @@ export default async function handler(req, res) {
|
||||
}
|
||||
|
||||
const origin = req.headers.origin;
|
||||
if (origin && origin !== ALLOWED_ORIGIN) {
|
||||
if (origin && !isAllowedOrigin(origin)) {
|
||||
return res.status(403).json({ error: 'Forbidden' });
|
||||
}
|
||||
|
||||
@@ -58,8 +56,7 @@ export default async function handler(req, res) {
|
||||
}
|
||||
|
||||
try {
|
||||
const sharingUrl = 'https://www.dropbox.com/scl/fi/usa8me7ywgylrij2bt6hj/Data-Matrix.xlsx?rlkey=tsec8csrhye54u1fdvk15ped1&dl=1';
|
||||
const upstream = await fetch(sharingUrl, {
|
||||
const upstream = await fetch(DROPBOX_SHARED_URL, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache',
|
||||
@@ -76,7 +73,11 @@ export default async function handler(req, res) {
|
||||
if (!upstream.ok) {
|
||||
const errText = await upstream.text();
|
||||
console.error('Dropbox URL error:', upstream.status, errText);
|
||||
return res.status(upstream.status).send('Dropbox error: ' + errText);
|
||||
return res.status(upstream.status).send(
|
||||
'Dropbox error: ' +
|
||||
errText +
|
||||
'\n\nSet DROPBOX_SHARED_URL in Vercel if the sharing link changed.'
|
||||
);
|
||||
}
|
||||
|
||||
const buffer = await upstream.arrayBuffer();
|
||||
|
||||
Reference in New Issue
Block a user