Skip to content

Commit fde5f4e

Browse files
authored
Sandbox widget & PHP 8.3.30 (#119)
* Bump serverless to get PHP 8.3.30 * Add widget with info for sandbox expiry
1 parent 04810bf commit fde5f4e

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

api/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ const serverlesswp = require('serverlesswp');
33
const { validate } = require('../util/install.js');
44
const { setup } = require('../util/directory.js');
55
const sqliteS3 = require('../util/sqliteS3.js');
6-
7-
const { register } = require('../util/goldilock.js');
6+
const goldilock = require('../util/goldilock.js');
87

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

5453
if (process.env['SERVERLESSWP_DATA_SECRET']) {
5554
sqliteS3Config.S3Client.endpoint = 'https://data.serverlesswp.com';
56-
sqliteS3Config.onAuthError = () => register(
55+
sqliteS3Config.onAuthError = () => goldilock.register(
5756
sqliteS3Config.bucket,
5857
process.env['SERVERLESSWP_DATA_SECRET']
5958
);
@@ -83,3 +82,8 @@ if (process.env['SQLITE_S3_BUCKET'] || process.env['SERVERLESSWP_DATA_SECRET'])
8382
// Register the sqlite serverlesswp plugin.
8483
serverlesswp.registerPlugin(sqliteS3);
8584
}
85+
86+
if (process.env['SERVERLESSWP_DATA_SECRET']) {
87+
// Register the goldilock widget plugin.
88+
serverlesswp.registerPlugin(goldilock);
89+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"dependencies": {
77
"@aws-sdk/client-s3": "^3.772.0",
8-
"serverlesswp": "^0.4.4",
8+
"serverlesswp": "^0.5.0",
99
"sqlite3": "^5.1.7"
1010
},
1111
"engines": {

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ServerlessWP puts PHP & WordPress in serverless functions. Deploy this repositor
88

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

11-
![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)
11+
![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)
1212

1313
## Quick Deploy
1414

util/goldilock.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
exports.name = 'Goldilock Widget';
12

23
exports.register = async function (bucket, secret) {
34
const response = await fetch('https://data.serverlesswp.com/auto-register', {
@@ -12,4 +13,25 @@ exports.register = async function (bucket, secret) {
1213
const errorText = await response.text();
1314
throw new Error(`Auto registration failed: ${errorText}`);
1415
}
16+
}
17+
18+
exports.postRequest = async function(event, response) {
19+
if (!response || !response.body) {
20+
return;
21+
}
22+
23+
const contentType = response.headers?.['content-type'] || response.headers?.['Content-Type'] || '';
24+
if (!contentType.includes('text/html')) {
25+
return;
26+
}
27+
28+
const widgetHtml = `
29+
<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;">
30+
<div style="font-weight:600;margin-bottom:4px;">Sandbox Database</div>
31+
<div style="color:#fbbf24;">Sandbox mode - database file will expire in a few hours.</div>
32+
</div>`;
33+
34+
if (response.body.includes('</body>')) {
35+
response.body = response.body.replace('</body>', widgetHtml + '</body>');
36+
}
1537
}

0 commit comments

Comments
 (0)