feat: Enhance CORS support by exposing important headers and update API responses to include Last-Modified and Content-Length-Source for improved client-side handling
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 5m14s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 5m14s
This commit is contained in:
@@ -14,6 +14,12 @@ app.use(cors());
|
|||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
|
|
||||||
|
// Expose important headers to browser JS (for CORS)
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
res.setHeader('Access-Control-Expose-Headers', 'ETag, Last-Modified, Content-Length-Source');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
// Serve static files from the React app
|
// Serve static files from the React app
|
||||||
app.use(express.static(path.join(__dirname, 'public')));
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
@@ -377,6 +383,11 @@ app.post('/api/asns', async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const put = await s3.putObject(params).promise();
|
const put = await s3.putObject(params).promise();
|
||||||
if (put.ETag) res.set('ETag', String(put.ETag));
|
if (put.ETag) res.set('ETag', String(put.ETag));
|
||||||
|
try {
|
||||||
|
const head = await s3.headObject({ Bucket: BUCKET_NAME, Key: 'bgp_data/asns.txt' }).promise();
|
||||||
|
if (head.LastModified) res.set('Last-Modified', new Date(head.LastModified).toUTCString());
|
||||||
|
if (typeof head.ContentLength === 'number') res.set('Content-Length-Source', String(head.ContentLength));
|
||||||
|
} catch {}
|
||||||
res.send('File updated successfully');
|
res.send('File updated successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -460,6 +471,11 @@ app.post('/api/domains-new', async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const put = await s3.putObject(params).promise();
|
const put = await s3.putObject(params).promise();
|
||||||
if (put.ETag) res.set('ETag', String(put.ETag));
|
if (put.ETag) res.set('ETag', String(put.ETag));
|
||||||
|
try {
|
||||||
|
const head = await s3.headObject({ Bucket: BUCKET_NAME, Key: 'bgp_data/domains_community.txt' }).promise();
|
||||||
|
if (head.LastModified) res.set('Last-Modified', new Date(head.LastModified).toUTCString());
|
||||||
|
if (typeof head.ContentLength === 'number') res.set('Content-Length-Source', String(head.ContentLength));
|
||||||
|
} catch {}
|
||||||
res.send('File updated successfully');
|
res.send('File updated successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -543,6 +559,11 @@ app.post('/api/ip-ranges', async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const put = await s3.putObject(params).promise();
|
const put = await s3.putObject(params).promise();
|
||||||
if (put.ETag) res.set('ETag', String(put.ETag));
|
if (put.ETag) res.set('ETag', String(put.ETag));
|
||||||
|
try {
|
||||||
|
const head = await s3.headObject({ Bucket: BUCKET_NAME, Key: 'bgp_data/ips.txt' }).promise();
|
||||||
|
if (head.LastModified) res.set('Last-Modified', new Date(head.LastModified).toUTCString());
|
||||||
|
if (typeof head.ContentLength === 'number') res.set('Content-Length-Source', String(head.ContentLength));
|
||||||
|
} catch {}
|
||||||
res.send('File updated successfully');
|
res.send('File updated successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user