This commit is contained in:
2025-09-10 02:50:32 +02:00
commit be3d896ca1
9 changed files with 235 additions and 0 deletions

34
.gitignore vendored Normal file
View File

@@ -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

15
README.md Normal file
View File

@@ -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.

29
bun.lock Normal file
View File

@@ -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=="],
}
}

17
index.html Normal file
View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Web Push</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>🚀 Test Web Push</h1>
<p>Ultra prosta strona do testowania Web Push notyfikacji</p>
</div>
<script src="http://localhost:8000/campaigns/webpush/integration/4c9eb80b-a074-45b2-8f15-397c1f7696da.js"></script>
</body>
</html>

16
package.json Normal file
View File

@@ -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"
}
}

77
server.ts Normal file
View File

@@ -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)");

27
style.css Normal file
View File

@@ -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;
}

5
sw.js Normal file
View File

@@ -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",
);

15
tsconfig.json Normal file
View File

@@ -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"]
}
}