Skip to content

Commit

Permalink
feat: create hiyasakamishiro
Browse files Browse the repository at this point in the history
  • Loading branch information
piro0919 committed Dec 11, 2024
1 parent 73236b4 commit 745998a
Show file tree
Hide file tree
Showing 14 changed files with 1,483 additions and 19 deletions.
43 changes: 43 additions & 0 deletions apps/hiyasakamishiro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

certificates
36 changes: 36 additions & 0 deletions apps/hiyasakamishiro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
16 changes: 16 additions & 0 deletions apps/hiyasakamishiro/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
];

export default eslintConfig;
44 changes: 44 additions & 0 deletions apps/hiyasakamishiro/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
async headers() {
return [
{
headers: [
{
key: "X-Content-Type-Options",
value: "nosniff",
},
{
key: "X-Frame-Options",
value: "DENY",
},
{
key: "Referrer-Policy",
value: "strict-origin-when-cross-origin",
},
],
source: "/(.*)",
},
{
headers: [
{
key: "Content-Type",
value: "application/javascript; charset=utf-8",
},
{
key: "Cache-Control",
value: "no-cache, no-store, must-revalidate",
},
{
key: "Content-Security-Policy",
value: "default-src 'self'; script-src 'self'",
},
],
source: "/sw.js",
},
];
},
};

export default nextConfig;
28 changes: 28 additions & 0 deletions apps/hiyasakamishiro/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"dependencies": {
"next": "15.1.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"web-push": "3.6.7"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"@types/web-push": "3.6.4",
"eslint": "^9",
"eslint-config-next": "15.1.0",
"typescript": "^5"
},
"name": "hiyasakamishiro",
"private": true,
"scripts": {
"build": "next build",
"dev": "next dev --turbopack",
"dev:https": "next dev --turbopack --experimental-https",
"lint": "next lint",
"start": "next start"
},
"version": "0.1.0"
}
22 changes: 22 additions & 0 deletions apps/hiyasakamishiro/public/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
self.addEventListener("push", function (event) {
if (event.data) {
const data = event.data.json();
const options = {
body: data.body,
icon: data.icon || "/icon.png",
badge: "/badge.png",
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: "2",
},
};
event.waitUntil(self.registration.showNotification(data.title, options));
}
});

self.addEventListener("notificationclick", function (event) {
console.log("Notification click received.");
event.notification.close();
event.waitUntil(clients.openWindow("<https://your-website.com>"));
});
55 changes: 55 additions & 0 deletions apps/hiyasakamishiro/src/app/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"use server";
import webpush from "web-push";

webpush.setVapidDetails(
"mailto:your-email@example.com",
process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY!,
process.env.VAPID_PRIVATE_KEY!,
);

let subscription: PushSubscription | null = null;

export async function subscribeUser(sub: PushSubscription) {
subscription = sub;

// In a production environment, you would want to store the subscription in a database
// For example: await db.subscriptions.create({ data: sub })
return { success: true };
}

export async function unsubscribeUser() {
subscription = null;

// In a production environment, you would want to remove the subscription from the database
// For example: await db.subscriptions.delete({ where: { ... } })
return { success: true };
}

export async function sendNotification(message: string) {
if (!subscription) {
throw new Error("No subscription available");
}

try {
await webpush.sendNotification(
{
endpoint: subscription.endpoint,
keys: {
auth: subscription.getKey("auth")?.toString() ?? "",
p256dh: subscription.getKey("p256dh")?.toString() ?? "",
},
},
JSON.stringify({
body: message,
icon: "/icon.png",
title: "Test Notification",
}),
);

return { success: true };
} catch (error) {
console.error("Error sending push notification:", error);

return { error: "Failed to send notification", success: false };
}
}
Binary file added apps/hiyasakamishiro/src/app/favicon.ico
Binary file not shown.
18 changes: 18 additions & 0 deletions apps/hiyasakamishiro/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Metadata } from "next";

export const metadata: Metadata = {
description: "Generated by create next app",
title: "Create Next App",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="ja">
<body>{children}</body>
</html>
);
}
25 changes: 25 additions & 0 deletions apps/hiyasakamishiro/src/app/manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { MetadataRoute } from "next";

export default function manifest(): MetadataRoute.Manifest {
return {
background_color: "#ffffff",
description: "A Progressive Web App built with Next.js",
display: "standalone",
icons: [
{
sizes: "192x192",
src: "/icon-192x192.png",
type: "image/png",
},
{
sizes: "512x512",
src: "/icon-512x512.png",
type: "image/png",
},
],
name: "Next.js PWA",
short_name: "NextPWA",
start_url: "/",
theme_color: "#000000",
};
}
Loading

0 comments on commit 745998a

Please sign in to comment.