I know this should be simple but its just not working. Any help will be appreciated.
I created bunny.js in content/adapters/storage.
It has the following code:
const BaseAdapter = require('ghost-storage-base');
const fetch = require('node-fetch');
class BunnyAdapter extends BaseAdapter {
constructor(config) {
super(config);
this.config = config;
this.storageUrl = config.bunny.storageUrl;
this.accessKey = config.bunny.accessKey;
this.storageZone = config.bunny.storageZone;
}
async exists(fileName) {
const response = await fetch(`${this.storageUrl}/${this.storageZone}/${fileName}`, {
method: 'HEAD',
headers: {
'AccessKey': this.accessKey
}
});
return response.ok;
}
async save(image, targetDir) {
const response = await fetch(`${this.storageUrl}/${this.storageZone}/${targetDir}/${image.name}`, {
method: 'PUT',
headers: {
'Content-Length': image.size,
'AccessKey': this.accessKey,
'Content-Type': image.type
},
body: image
});
if (!response.ok) {
throw new Error(`BunnyCDN storage adapter failed to save file ${image.name}`);
}
return `${this.config.bunny.cdnUrl}/${this.storageZone}/${targetDir}/${image.name}`;
}
async serve(options) {
return function customServe(req, res, next) {
next();
}
}
async delete(fileName) {
const response = await fetch(`${this.storageUrl}/${this.storageZone}/${fileName}`, {
method: 'DELETE',
headers: {
'AccessKey': this.accessKey
}
});
if (!response.ok) {
throw new Error(`BunnyCDN storage adapter failed to delete file ${fileName}`);
}
}
async read(options) {
const response = await fetch(`${this.storageUrl}/${this.storageZone}/${options.path}`, {
method: 'GET',
headers: {
'AccessKey': this.accessKey
}
});
if (!response.ok) {
throw new Error(`BunnyCDN storage adapter failed to read file ${options.path}`);
}
return response.text();
}
}
module.exports = BunnyAdapter;
Then i edit the config.production.json
It looks like this
{
"url": "https://xxxxx.com",
"server": {
"port": 2368,
"host": "127.0.0.1"
},
"database": {
"client": "mysql",
"connection": {
"host": "localhost",
"user": "ghost-621",
"password": "Y6})!vARmiCRGY5e)Mq>",
"port": 3306,
"database": "ghost_production"
}
},
"mail": {
"transport": "Direct"
},
"logging": {
"transports": [
"file",
"stdout"
]
},
"process": "systemd",
"paths": {
"contentPath": "/var/www/ghost/content",
}
"storage": {
"active": "bunny",
"bunny": {
"cdnUrl": "web.b-cdn.net",
"storageUrl": "storage.bunnycdn.com",
"accessKey": "xxxxxxx",
"storageZone": "xxxxxx",
"adapter": "bunny"
}
}
I get the Bad Gateway 502 on the front end
The following in the ghost error log, it doesnt really tell me whre the error is
“code”:“ERR_INVALID_ARG_TYPE”,“message”:“The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received undefined”,“context”:“"Checking for updates failed, your site will continue to function."”,“help”:“"If you get this error repeatedly, please seek help from https://ghost.org/docs/\”",“stack”:“TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received undefined\n at new NodeError (node:internal/errors:387:5)\n at Function.byteLength (node:buffer:740:11)\n at UpdateCheckService.updateCheckRequest (/var/www/ghost/versions/5.36.0/node_modules/@tryghost/update-check-service/lib/update-check-service.js:159:55)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async UpdateCheckService.check (/var/www/ghost/versions/5.36.0/node_modules/@tryghost/update-check-service/lib/update-check-service.js:362:30)\n at async module.exports (/var/www/ghost/versions/5.36.0/core/server/update-check.js:60:5)”},“msg”:"The "string" argument must be of type string or an instance of Buffer or ArrayBuffer.