BREAKING CHANGE(typedserver): Migrate to new push.rocks packages and async smartfs API; replace smartchok with smartwatch; update deps and service worker handling

This commit is contained in:
2025-12-02 09:16:42 +00:00
parent bce84c6838
commit 8557c769fa
11 changed files with 1478 additions and 1072 deletions

View File

@@ -92,7 +92,7 @@ export class HandlerStatic extends Handler {
// lets actually care about serving, if security checks pass
let fileBuffer: Buffer;
try {
fileBuffer = plugins.smartfile.fs.toBufferSync(joinedPath);
fileBuffer = await plugins.fsInstance.file(joinedPath).read() as Buffer;
usedPath = joinedPath;
} catch (err) {
// try serving index.html instead
@@ -101,7 +101,7 @@ export class HandlerStatic extends Handler {
console.log(`serving default path ${defaultPath} instead of ${joinedPath}`);
try {
parsedPath = plugins.path.parse(defaultPath);
fileBuffer = plugins.smartfile.fs.toBufferSync(defaultPath);
fileBuffer = await plugins.fsInstance.file(defaultPath).read() as Buffer;
usedPath = defaultPath;
} catch (err) {
res.writeHead(500);

View File

@@ -6,17 +6,32 @@ import { Handler } from './classes.handler.js';
import type { TypedServer } from '../classes.typedserver.js';
import { HandlerTypedRouter } from './classes.handlertypedrouter.js';
const swBundleJs: string = plugins.smartfile.fs.toStringSync(
plugins.path.join(paths.serviceworkerBundleDir, './serviceworker.bundle.js')
);
const swBundleJsMap: string = plugins.smartfile.fs.toStringSync(
plugins.path.join(paths.serviceworkerBundleDir, './serviceworker.bundle.js.map')
);
// Lazy-loaded service worker bundle content
let swBundleJs: string | null = null;
let swBundleJsMap: string | null = null;
const loadServiceWorkerBundle = async (): Promise<void> => {
if (swBundleJs === null) {
swBundleJs = await plugins.fsInstance
.file(plugins.path.join(paths.serviceworkerBundleDir, './serviceworker.bundle.js'))
.encoding('utf8')
.read() as string;
}
if (swBundleJsMap === null) {
swBundleJsMap = await plugins.fsInstance
.file(plugins.path.join(paths.serviceworkerBundleDir, './serviceworker.bundle.js.map'))
.encoding('utf8')
.read() as string;
}
};
let swVersionInfo: interfaces.serviceworker.IRequest_Serviceworker_Backend_VersionInfo['response'] =
null;
const serviceworkerHandler = new Handler(
'GET',
async (req, res) => {
await loadServiceWorkerBundle();
if (req.path === '/serviceworker.bundle.js') {
res.status(200);
res.set('Content-Type', 'text/javascript');