commit be3d896ca1738969dc37db493444bcabfe8e5653 Author: GarandPLG Date: Wed Sep 10 02:50:32 2025 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a14702c --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +# dependencies (bun install) +node_modules + +# output +out +dist +*.tgz + +# code coverage +coverage +*.lcov + +# logs +logs +_.log +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# caches +.eslintcache +.cache +*.tsbuildinfo + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..a150a70 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# test-web-push + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.2.20. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime. diff --git a/bun.lock b/bun.lock new file mode 100644 index 0000000..962d0e1 --- /dev/null +++ b/bun.lock @@ -0,0 +1,29 @@ +{ + "lockfileVersion": 1, + "workspaces": { + "": { + "name": "test-web-push", + "devDependencies": { + "@types/bun": "latest", + }, + "peerDependencies": { + "typescript": "^5", + }, + }, + }, + "packages": { + "@types/bun": ["@types/bun@1.2.21", "", { "dependencies": { "bun-types": "1.2.21" } }, "sha512-NiDnvEqmbfQ6dmZ3EeUO577s4P5bf4HCTXtI6trMc6f6RzirY5IrF3aIookuSpyslFzrnvv2lmEWv5HyC1X79A=="], + + "@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + + "@types/react": ["@types/react@19.1.12", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-cMoR+FoAf/Jyq6+Df2/Z41jISvGZZ2eTlnsaJRptmZ76Caldwy1odD4xTr/gNV9VLj0AWgg/nmkevIyUfIIq5w=="], + + "bun-types": ["bun-types@1.2.21", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-sa2Tj77Ijc/NTLS0/Odjq/qngmEPZfbfnOERi0KRUYhT9R8M4VBioWVmMWE5GrYbKMc+5lVybXygLdibHaqVqw=="], + + "csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="], + + "typescript": ["typescript@5.9.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A=="], + + "undici-types": ["undici-types@7.10.0", "", {}, "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag=="], + } +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..a7d19c4 --- /dev/null +++ b/index.html @@ -0,0 +1,17 @@ + + + + + + Test Web Push + + + +
+

🚀 Test Web Push

+

Ultra prosta strona do testowania Web Push notyfikacji

+
+ + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..7fca4f6 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "test-web-push", + "version": "1.0.0", + "type": "module", + "private": true, + "scripts": { + "dev": "bun run server.ts", + "start": "bun run dev" + }, + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.9.2" + } +} diff --git a/server.ts b/server.ts new file mode 100644 index 0000000..82eacfd --- /dev/null +++ b/server.ts @@ -0,0 +1,77 @@ +// server.ts + +const server = Bun.serve({ + port: 5173, + async fetch(req) { + const url = new URL(req.url); + const pathname = url.pathname; + + // Helper function to get MIME type + function getMimeType(filename: string): string { + const ext = filename.split(".").pop()?.toLowerCase(); + switch (ext) { + case "js": + return "application/javascript"; + case "ts": + return "application/javascript"; + case "css": + return "text/css"; + case "html": + return "text/html"; + case "json": + return "application/json"; + case "png": + return "image/png"; + case "jpg": + case "jpeg": + return "image/jpeg"; + case "svg": + return "image/svg+xml"; + case "ico": + return "image/x-icon"; + default: + return "text/plain"; + } + } + + // Serve root as index.html + if (pathname === "/") + try { + const file = Bun.file("./index.html"); + return new Response(file, { + headers: { + "Content-Type": "text/html", + }, + }); + } catch (error) { + return new Response("Index file not found", { status: 404 }); + } + + // Serve other files + const filename = pathname.startsWith("/") ? pathname.slice(1) : pathname; + try { + const file = Bun.file(`./${filename}`); + const exists = await file.exists(); + + if (!exists) + return new Response(`File not found: ${filename}`, { status: 404 }); + + const mimeType = getMimeType(filename); + + return new Response(file, { + headers: { + "Content-Type": mimeType, + }, + }); + } catch (error) { + console.error(`Error serving ${filename}:`, error); + return new Response("Internal Server Error", { status: 500 }); + } + }, +}); + +console.log(`🚀 Server running at http://localhost:${server.port}`); +console.log("📋 Available routes:"); +console.log(" - / (index.html)"); +console.log(" - /sw.js (Service Worker)"); +console.log(" - /style.css (Styles)"); diff --git a/style.css b/style.css new file mode 100644 index 0000000..8e5026b --- /dev/null +++ b/style.css @@ -0,0 +1,27 @@ +body { + font-family: Arial, sans-serif; + max-width: 800px; + margin: 50px auto; + padding: 20px; + line-height: 1.6; +} +.container { + background: #f4f4f4; + padding: 30px; + border-radius: 10px; +} +h1 { + color: #333; + text-align: center; +} +p { + color: #666; + text-align: center; +} +.status { + background: white; + padding: 15px; + border-radius: 5px; + margin: 20px 0; + border-left: 4px solid #007cba; +} diff --git a/sw.js b/sw.js new file mode 100644 index 0000000..75189f6 --- /dev/null +++ b/sw.js @@ -0,0 +1,5 @@ +// sw.js +console.log("Service Worker loaded"); +importScripts( + "http://localhost:8000/campaigns/webpush/sw-core/4c9eb80b-a074-45b2-8f15-397c1f7696da.js", +); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..cfd3356 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "noEmit": true, + "strict": true, + "skipLibCheck": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + "lib": ["ES2022", "DOM", "WebWorker"], + "types": ["bun-types"] + } +}