Burner
02/13/2023, 8:02 PMBurner
02/13/2023, 8:04 PMBurner
02/13/2023, 8:05 PMBurner
02/13/2023, 8:15 PMaa
02/13/2023, 8:18 PMTaurlon
02/13/2023, 9:52 PMdave
02/14/2023, 12:42 AMdave
02/14/2023, 5:39 AMdave
02/14/2023, 5:39 AMdave
02/14/2023, 5:44 AMdave
02/14/2023, 5:58 AMNoodles
02/14/2023, 6:07 AMAccess-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST
and also modified the worker function to include it as well
response.headers.set('Access-Control-Allow-Origin', '*');
Example will be from
So when I try to click the "disable" button it should do the following and pass along the name/version of the plugin which was in the row of the table the button was clicked on.
disableButton.addEventListener('click', async () => {
const response = await fetch('https://license.bghddevelopment.workers.dev/api/plugins/disable', {
method: 'POST',
body: JSON.stringify({ name: plugin.name, version: plugin.version }),
headers: { 'Content-Type': 'application/json' },
mode: 'cors',
})
const result = await response.json()
if (result.success) {
enabledCell.textContent = 'No'
disableButton.disabled = true
enableButton.disabled = false
} else {
console.error('Failed to disable plugin')
}
})
Then the worker runs for example this (I know this is enable, disable is the exact same but changed to disable)
if (pathname === '/api/plugins/enable') {
console.log(`Enabling plugin: ${pluginName}, version: ${pluginVersion}`);
const licenseKeyKey = `${pluginName}-${pluginVersion}`;
const plugin = await LICENSE_KEY_KV.get(licenseKeyKey, { type: 'json' });
if (!plugin) {
const response = new Response(`Plugin ${pluginName}, version ${pluginVersion} not found`, { status: 404 });
response.headers.set('Access-Control-Allow-Origin', '*');
return response;
}
if (plugin.enabled) {
const response = new Response(`Plugin ${pluginName}, version ${pluginVersion} is already enabled`, { status: 400 });
response.headers.set('Access-Control-Allow-Origin', '*');
return response;
}
const newPlugin = {...plugin, enabled: true};
await LICENSE_KEY_KV.put(licenseKeyKey, JSON.stringify(newPlugin));
const response = new Response(`Plugin ${pluginName}, version ${pluginVersion} enabled`);
response.headers.set('Access-Control-Allow-Origin', '*');
return response;
}
Hopefully this makes decent sense, any advice is appreciated.kian
02/14/2023, 6:09 AMOPTIONS
requestskian
02/14/2023, 6:11 AMOPTIONS
Noodles
02/14/2023, 6:15 AMnwdles
02/14/2023, 8:03 AMlet options = { cf: { polish: 'lossless', image: {format: 'webp'} } }
? i need to enable speed->optimization->image resizing for any of domains?lasseschou
02/14/2023, 8:20 AMkian
02/14/2023, 8:22 AMlasseschou
02/14/2023, 8:24 AMJatinGundabathula
02/14/2023, 9:20 AMHardAtWork
02/14/2023, 9:22 AMJatinGundabathula
02/14/2023, 9:23 AMHardAtWork
02/14/2023, 9:24 AMfetch
to bypass cache next time, but you can't bypass cache on the first request.HardAtWork
02/14/2023, 9:24 AMcacheTtl
to 0, which means next time you request it, it will go to the origin.JatinGundabathula
02/14/2023, 9:28 AMHardAtWork
02/14/2023, 9:31 AMcacheKey
, CF will just use the Request URL instead.Mees
02/14/2023, 10:46 AMSkye
02/14/2023, 10:47 AMworkers_dev = false