Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.1 release #1

Merged
merged 3 commits into from
Mar 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add files via upload
  • Loading branch information
sippedaway authored Mar 11, 2025
commit c55859048d6aa6415c6ab291d0e029a853cd5c2b
22 changes: 21 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const PORT = 3000;

const CONTENTFUL_SPACE_ID = process.env.CONTENTFUL_SPACE_ID;
const CONTENTFUL_ACCESS_TOKEN = process.env.CONTENTFUL_ACCESS_TOKEN;
const COUNTERAPI_AUTHKEY = process.env.COUNTERAPI_AUTHKEY;

app.use(cors());
app.use(express.static(path.join(__dirname, 'public')));
Expand All @@ -18,6 +19,25 @@ app.get('/', (req, res) => {
app.get('/:id', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'post.html'));
});


app.get('/api/views/:postId', async (req, res) => {
const postId = req.params.postId;
const apiUrl = `https://counter.sipped.org/punch/sippedblog/${COUNTERAPI_AUTHKEY}/${postId}`;
try {
const response = await fetch(apiUrl);
const data = await response.json();
res.json(data);
} catch (err) {
console.error('Ersror fetching view count:', err.message);
res.status(500).json({
error: 'Error fetching view count',
details: err.message,
count: 0
});
}
});

app.get('/api/posts', async (req, res) => {
const apiUrl = `https://cdn.contentful.com/spaces/${CONTENTFUL_SPACE_ID}/entries?access_token=${CONTENTFUL_ACCESS_TOKEN}&content_type=post`;
try {
Expand All @@ -32,7 +52,7 @@ app.get('/api/posts', async (req, res) => {

app.get('/api/posts/:postId', async (req, res) => {
const postId = req.params.postId;
const apiUrl = `https://cdn.contentful.com/spaces/${CONTENTFUL_SPACE_ID}/entries/${postId}?access_token=${CONTENTFUL_ACCESS_TOKEN}&include=2`;
const apiUrl = `https://cdn.contentful.com/spaces/${CONTENTFUL_SPACE_ID}/entries/${postId}?access_token=${CONTENTFUL_ACCESS_TOKEN}&include=3`;
try {
const response = await fetch(apiUrl);
const data = await response.json();
Expand Down