Skip to content

Commit cae0f6f

Browse files
committed
chore: Fix Cloudflare cache buster script.
1 parent c16594f commit cae0f6f

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

config/hooks/post-receive-production

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ repo_checkout_tag ${LAST_TAG}
2424

2525
# 2. install node packages
2626
npm_install ${LAST_TAG}
27-
npm_build ${LAST_TAG} prod /var/www/website/${DEPLOY_ENV}/config.json /var/www/website/${DEPLOY_ENV}/build.json
27+
npm_build ${LAST_TAG} prod /var/www/website/production/config.json /var/www/website/production/build.json
2828

2929
# 3. change symlink
3030
repo_link ${LAST_TAG}
3131

3232
# 5. post scripts
33-
post_scripts ${LAST_TAG} /var/www/website/${DEPLOY_ENV}/config.json /var/www/website/${DEPLOY_ENV}/build.json
33+
post_scripts ${LAST_TAG} /var/www/website/production/config.json /var/www/website/production/build.json
3434

3535
# 4. cleanup old deployment
3636
repo_cleanup "v[0-9]+\.[0-9]+\.[0-9]+"

scripts/cloudflare-deploy.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,27 @@ const buildConfig = require(process.env.BUILD_CONFIG && existsSync(process.env.B
3131
if (buildConfig.cloudflare && buildConfig.cloudflare.enabled && buildConfig.cloudflare.authKey) {
3232
(async () => {
3333
try {
34-
const client = axios.create({ baseURL: 'https://api.cloudflare.com/client/v4' });
35-
36-
// purge cache
37-
await client.post('/zones/' + buildConfig.cloudflare.zoneId + '/purge_cache', {
38-
hosts: [ websiteConfig.webUri.hostname ]
39-
}, {
34+
const client = axios.create({
35+
baseURL: 'https://api.cloudflare.com/client/v4',
4036
headers: {
4137
'X-Auth-Key': buildConfig.cloudflare.authKey,
4238
'X-Auth-Email': buildConfig.cloudflare.authEmail,
4339
'Content-Type': 'application/json'
4440
}
4541
});
42+
43+
// purge cache
44+
await client.post('/zones/' + buildConfig.cloudflare.zoneId + '/purge_cache', { purge_everything: true });
45+
4646
// eslint-disable-next-line no-console
47-
console.log('Purge Cloudflare cache for %s.', websiteConfig.webUri.hostname);
47+
console.log('Purged Cloudflare cache for %s.', websiteConfig.webUri.hostname);
4848
process.exit(0);
4949

5050
} catch (err) {
5151
// eslint-disable-next-line no-console
52-
console.error('Cloudflare error: %s', JSON.stringify(err));
52+
console.error('Cloudflare error: %s', err);
53+
// eslint-disable-next-line no-console
54+
console.error(err && err.response && err.response.data ? JSON.stringify(err.response.data, null, ' ') : err);
5355
process.exit(1);
5456
}
5557
})();

0 commit comments

Comments
 (0)