Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const serverlesswp = require('serverlesswp');
const { validate } = require('../util/install.js');
const { setup } = require('../util/directory.js');
const sqliteS3 = require('../util/sqliteS3.js');

const { register } = require('../util/goldilock.js');
const goldilock = require('../util/goldilock.js');

const pathToWP = '/tmp/wp';
let initSqliteS3 = false;
Expand Down Expand Up @@ -53,7 +52,7 @@ exports.handler = async function (event, context, callback) {

if (process.env['SERVERLESSWP_DATA_SECRET']) {
sqliteS3Config.S3Client.endpoint = 'https://data.serverlesswp.com';
sqliteS3Config.onAuthError = () => register(
sqliteS3Config.onAuthError = () => goldilock.register(
sqliteS3Config.bucket,
process.env['SERVERLESSWP_DATA_SECRET']
);
Expand Down Expand Up @@ -83,3 +82,8 @@ if (process.env['SQLITE_S3_BUCKET'] || process.env['SERVERLESSWP_DATA_SECRET'])
// Register the sqlite serverlesswp plugin.
serverlesswp.registerPlugin(sqliteS3);
}

if (process.env['SERVERLESSWP_DATA_SECRET']) {
// Register the goldilock widget plugin.
serverlesswp.registerPlugin(goldilock);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"dependencies": {
"@aws-sdk/client-s3": "^3.772.0",
"serverlesswp": "^0.4.4",
"serverlesswp": "^0.5.0",
"sqlite3": "^5.1.7"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ServerlessWP puts PHP & WordPress in serverless functions. Deploy this repositor

Stay up-to-date at the ServerlessWP repository: [github.com/mitchmac/serverlesswp](https://github.com/mitchmac/serverlesswp)

![PHP 8.3.29](https://img.shields.io/badge/version-8.3.29-blue?logo=php&labelColor=white) ![WordPress 6.8.1](https://img.shields.io/badge/version-6.8.1-blue?logo=wordpress&labelColor=white&logoColor=black)
![PHP 8.3.30](https://img.shields.io/badge/version-8.3.30-blue?logo=php&labelColor=white) ![WordPress 6.8.1](https://img.shields.io/badge/version-6.8.1-blue?logo=wordpress&labelColor=white&logoColor=black)

## Quick Deploy

Expand Down
22 changes: 22 additions & 0 deletions util/goldilock.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exports.name = 'Goldilock Widget';

exports.register = async function (bucket, secret) {
const response = await fetch('https://data.serverlesswp.com/auto-register', {
Expand All @@ -12,4 +13,25 @@ exports.register = async function (bucket, secret) {
const errorText = await response.text();
throw new Error(`Auto registration failed: ${errorText}`);
}
}

exports.postRequest = async function(event, response) {
if (!response || !response.body) {
return;
}

const contentType = response.headers?.['content-type'] || response.headers?.['Content-Type'] || '';
if (!contentType.includes('text/html')) {
return;
}

const widgetHtml = `
<div id="goldilock-widget" style="position:fixed;bottom:20px;right:20px;background:#1a1a1a;color:#fff;padding:12px 16px;border-radius:8px;font-family:system-ui,-apple-system,sans-serif;font-size:14px;box-shadow:0 4px 12px rgba(0,0,0,0.3);z-index:999999;max-width:250px;">
<div style="font-weight:600;margin-bottom:4px;">Sandbox Database</div>
<div style="color:#fbbf24;">Sandbox mode - database file will expire in a few hours.</div>
</div>`;

if (response.body.includes('</body>')) {
response.body = response.body.replace('</body>', widgetHtml + '</body>');
}
}
Loading