Skip to content

Commit

Permalink
Update Deno, remove stats
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoBernardino committed Jan 21, 2023
1 parent 9a0a05c commit 39df07c
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .dvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.25.3
1.29.1
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@v1
with:
deno-version: v1.25.3
deno-version: v1.29.1
- run: |
make test
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: start
start:
deno run --watch --allow-net --allow-read=public,pages,.env,.env.defaults --allow-env main.ts
deno run --watch --allow-net --allow-read=public,pages,.env,.env.defaults,.env.example --allow-env main.ts

.PHONY: format
format:
Expand All @@ -10,4 +10,4 @@ format:
test:
deno fmt --check
deno lint
deno test --allow-net --allow-read=public,pages,.env,.env.defaults --allow-env --check=all
deno test --allow-net --allow-read=public,pages,.env,.env.defaults,.env.example --allow-env --check=all
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ It's not compatible with Loggit v1 (not end-to-end encrypted), which you can sti

## Requirements

This was tested with `deno@1.25.3`, though it's possible older versions might work.
This was tested with `deno`'s version in the `.dvmrc` file, though it's possible other versions might work.

There are no other dependencies. **Deno**!

Expand Down
4 changes: 3 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@
"public/js/userbase.js.map"
]
}
}
},
"importMap": "./import_map.json",
"lock": false
}
8 changes: 8 additions & 0 deletions import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"imports": {
"/": "./",
"./": "./",

"std/": "https://deno.land/[email protected]/"
}
}
21 changes: 1 addition & 20 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'https://deno.land/std@0.156.0/dotenv/load.ts';
import 'std/dotenv/load.ts';

import header from '../components/header.ts';
import footer from '../components/footer.ts';
Expand Down Expand Up @@ -211,22 +211,3 @@ export function calculateFrequencyFromGrouppedEvent(groupedEvent: GroupedEvent)

return `${frequencyNumberPerDay}x / day`;
}

export async function recordPageView(pathname: string) {
try {
await fetch('https://stats.onbrn.com/api/event', {
method: 'POST',
headers: {
'content-type': 'application/json; charset=utf-8',
},
body: JSON.stringify({
domain: baseUrl.replace('https://', ''),
name: 'pageview',
url: `${baseUrl}${pathname}`,
}),
});
} catch (error) {
console.log('Failed to log pageview');
console.error(error);
}
}
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { serve } from 'https://deno.land/std@0.156.0/http/server.ts';
import { serve } from 'std/http/server.ts';
import routes, { Route } from './routes.ts';

function handler(request: Request) {
Expand Down
2 changes: 1 addition & 1 deletion main_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from 'https://deno.land/std@0.156.0/testing/asserts.ts';
import { assertEquals } from 'std/testing/asserts.ts';
import { abortController } from './main.ts';

const baseUrl = 'http://localhost:8000';
Expand Down
23 changes: 5 additions & 18 deletions routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { serveFile } from 'https://deno.land/std@0.156.0/http/file_server.ts';
import { baseUrl, basicLayoutResponse, PageContentResult, recordPageView } from './lib/utils.ts';
import { serveFile } from 'std/http/file_server.ts';
import { baseUrl, basicLayoutResponse, PageContentResult } from './lib/utils.ts';

// NOTE: This won't be necessary once https://github.com/denoland/deploy_feedback/issues/1 is closed
import * as indexPage from './pages/index.ts';
Expand Down Expand Up @@ -36,10 +36,6 @@ function createBasicRouteHandler(id: string, pathname: string) {
// @ts-ignore necessary because of the comment above
const { pageContent, pageAction } = pages[id];

if (!request.url.startsWith('http://localhost')) {
recordPageView(match.pathname.input);
}

if (request.method !== 'GET') {
return pageAction(request, match) as Response;
}
Expand Down Expand Up @@ -95,25 +91,16 @@ const routes: Routes = {

return new Response(sitemapContent, {
headers: {
'content-type': 'application/xml',
'content-type': 'application/xml; charset=utf-8',
'cache-control': `max-age=${oneDayInSeconds}, public`,
},
});
},
},
robots: {
pattern: new URLPattern({ pathname: '/robots.txt' }),
handler: async (_request) => {
const fileContents = await Deno.readTextFile(`public/robots.txt`);

const oneDayInSeconds = 24 * 60 * 60;

return new Response(fileContents, {
headers: {
'content-type': 'text/plain',
'cache-control': `max-age=${oneDayInSeconds}, public`,
},
});
handler: (request) => {
return serveFile(request, `public/robots.txt`);
},
},
public: {
Expand Down

0 comments on commit 39df07c

Please sign in to comment.