Skip to content

Commit

Permalink
feat(backend): host privacy policy on the back-end
Browse files Browse the repository at this point in the history
Since I am forced by Google's OAuth2 to have a back-end, I might as well
host the README.md policy there. Otherwise, I would have to separately
maintain GitHub pages, and separate domains (because it would be tricky
to host GitHub pages and auth backend endpoint on the same domain).
  • Loading branch information
maxpatiiuk committed Apr 14, 2024
1 parent 644fef0 commit f99fda1
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ Editing the layout
Npm 8
```

2. Complete installation steps in [./auth-backend](./auth-backend/)
2. Complete installation steps in [./backend](./backend/)

3. Complete installation steps in [./src](./src/)
File renamed without changes.
9 changes: 4 additions & 5 deletions auth-backend/README.md → backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This backend is used to generate a more-persistent token.
```sh
git clone https://github.com/maxpatiiuk/calendar-plus
cd calendar-plus
cd auth-backend
cd backend
```

2. Create
Expand All @@ -26,8 +26,8 @@ This backend is used to generate a more-persistent token.
- For development set:
- Authorized redirect URIs: `https://calendar-plus.patii.uk/api/route`
- For production set:
- Authorized JavaScript origins: set to domain on which `auth-backend` will
be hosted (`https://calendar-plus.patii.uk`)
- Authorized JavaScript origins: set to domain on which `backend` will be
hosted (`https://calendar-plus.patii.uk`)

3. Copy [./example.config.js](./example.config.js) into `./config.js` and fill
it in according to instructions in that file and the credentials you received
Expand All @@ -47,5 +47,4 @@ This backend is used to generate a more-persistent token.
### Production

1. Create new vercel.com project from this repository
2. Change the "Root Directory" setting to current directory
(/packages/auth-backend)
2. Change the "Root Directory" setting to current directory (/packages/backend)
File renamed without changes.
7 changes: 7 additions & 0 deletions backend/app/docs/privacy/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use server';

import { markdownToJsx } from '../../../utils/markdownToHtml';

export default async function MainPage(): Promise<JSX.Element> {
return markdownToJsx('../docs/privacy/README.md');
}
14 changes: 14 additions & 0 deletions backend/app/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client';

import React from 'react';

import { Metadata } from 'next';
import { localization } from '../const/localization';

export default function Error({ error }: { error: Error }): JSX.Element {
return <h1>{String(error)}</h1>;
}

export const metadata: Metadata = {
title: localization.unexpectedErrorHasOccurred,
};
Binary file added backend/app/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions backend/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';

import { baseUrl, robots, twitter } from '../const/siteConfig';
import { Metadata, Viewport } from 'next';
import { localization } from '../const/localization';

export default function RootLayout({
children,
}: {
readonly children: React.ReactNode;
}): JSX.Element {
return (
<html lang="en-US">
<body style={{ minHeight: '100vh', margin: 0, background: 'black' }}>
{children}
</body>
</html>
);
}

export const metadata: Metadata = {
title: {
default: localization.siteTitle,
template: `%s | ${localization.siteTitle}`,
},
description: localization.siteDescription,
applicationName: localization.siteTitle,
keywords: localization.siteKeywords,
creator: localization.siteAuthor,
generator: 'Next.js',
robots,
twitter: {
card: 'summary_large_image',
site: twitter,
creator: twitter,
},
metadataBase: new URL(baseUrl),
};

export const viewport: Viewport = {
colorScheme: 'light',
};
12 changes: 12 additions & 0 deletions backend/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

import { localization } from '../const/localization';
import { Metadata } from 'next';

export default function NotFound(): JSX.Element {
return <h1>{localization.notFound}</h1>;
}

export const metadata: Metadata = {
title: localization.notFound,
};
7 changes: 7 additions & 0 deletions backend/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use server';

import { markdownToJsx } from '../utils/markdownToHtml';

export default async function MainPage(): Promise<JSX.Element> {
return markdownToJsx('../README.md');
}
10 changes: 10 additions & 0 deletions backend/const/localization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const localization = {
siteTitle: 'Calendar Plus',
siteDescription:
'Google Calendar extension that provides insights into where your time goes. Includes power user tools, data export and customization',
siteKeywords:
'Calendar Plus, Google Calendar, Google Chrome, productivity, time management, time tracking, data export, insights, analytics, power user, customization',
siteAuthor: 'Max Patiiuk',
notFound: 'Page not found',
unexpectedErrorHasOccurred: 'An unexpected error has occurred',
};
10 changes: 10 additions & 0 deletions backend/const/siteConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const robots = { index: true, follow: true } as const;
export const privatePage = { index: false, follow: false } as const;
export const twitter = '@maxpatiiuk';
export const githubRepository = 'maxpatiiuk/calendar-plus';

export const baseUrl =
typeof process.env.VERCEL_URL === 'string' &&
process.env.VERCEL_URL.length > 0
? `https://${process.env.VERCEL_URL}`
: 'http://localhost:3000';
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export const googleClientRedirectUrl='https://kgbbebdcmdgkbopcffmpgkgcmcoomhmh.c
// origins by setting ACCESS_CONTROL_ALLOW_ORIGIN=*
export const accessControlAllowOrigin='chrome-extension://kgbbebdcmdgkbopcffmpgkgcmcoomhmh';

// The URL at which the /api/auth endpoint from the auth-backend is hosted
// The URL at which the /api/auth endpoint from the backend is hosted
export const productionAuthUrl = 'https://calendar-plus.patii.uk/api/auth';
export const developmentAuthUrl = 'http://localhost:3000/api/auth';
File renamed without changes.
28 changes: 26 additions & 2 deletions auth-backend/package-lock.json → backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion auth-backend/package.json → backend/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "calendar-stats-auth-backend",
"name": "calendar-stats-backend",
"private": true,
"license": "MIT",
"type": "module",
Expand All @@ -21,6 +21,8 @@
"type-check": "tsc"
},
"dependencies": {
"github-markdown-css": "^5.5.1",
"marked": "^12.0.1",
"next": "^14.2.1"
},
"devDependencies": {
Expand Down
6 changes: 1 addition & 5 deletions auth-backend/tsconfig.json → backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"include": [
"**/*.ts",
".next/types/**/*.ts",
"next-env.d.ts"
],
"include": ["**/*.ts", ".next/types/**/*.ts", "next-env.d.ts"],
"extends": "../tsconfig.json",
"compilerOptions": {
"incremental": true,
Expand Down
46 changes: 46 additions & 0 deletions backend/utils/markdownToHtml.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { githubRepository } from '../const/siteConfig';
import { marked } from 'marked';
import fs from 'node:fs/promises';

import 'github-markdown-css';

// Make relative URLs be relative to the GitHub repository
marked.use({
renderer: {
image(href, title, text) {
const url = new URL(
href,
`https://github.com/${githubRepository}/raw/main/`,
);
return `<img src="${url}" alt="${text}" title="${title}">`;
},
link(href, title, text) {
const url = new URL(
href,
`https://github.com/${githubRepository}/tree/main/`,
);
return `<a href="${url}" title="${title}">${text}</a>`;
},
},
});

export async function markdownToHtml(path: string): Promise<string> {
const content = await fs.readFile(path, 'utf8');
return marked(content, { gfm: true, breaks: false });
}

export async function markdownToJsx(path: string): Promise<JSX.Element> {
const content = await markdownToHtml(path);
return (
<div
className="markdown-body"
style={{ padding: '2rem', display: 'flex', justifyContent: 'center' }}
>
<main
id="content"
style={{ maxWidth: '50rem' }}
dangerouslySetInnerHTML={{ __html: content }}
/>
</div>
);
}
56 changes: 0 additions & 56 deletions index.html

This file was deleted.

2 changes: 1 addition & 1 deletion src/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
developmentAuthUrl,
productionAuthUrl,
googleClientId,
} from '../auth-backend/config.js';
} from '../backend/config.js';
import { fileURLToPath } from 'url';

const outputPath = path.resolve(
Expand Down

0 comments on commit f99fda1

Please sign in to comment.