Skip to content

Commit

Permalink
Feature: Live service check on forum-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
a2937 committed Nov 7, 2023
1 parent 1f5478f commit a1c5406
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions apps/forum-proxy/server.mjs
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';

import 'dotenv/config';
import cors from 'cors';
import fetch from 'node-fetch';
import express from 'express';

const app = express();

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

app.get('/', (req, res) => {
res.sendFile(join(__dirname, './views/index.html'));
})

app.use(cors({optionsSuccessStatus: 200}));
app.get('/latest', (req, res, next) => {
fetch('https://forum.freecodecamp.org/latest.json')
.then(response => response.json())
.then(data => {
res.json(data);
})
.catch(err => next(err));
});

app.use((req, res) => res.status(404).send('not found'));

app.use((err, req, res) => res.status(500).json(err));

const portNum = process.env.PORT || 3000;

app.listen(portNum, function() {
console.log(`Your app is listening on port ${portNum}`);
});

export default app;
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';

import 'dotenv/config';
import cors from 'cors';
import fetch from 'node-fetch';
import express from 'express';

const app = express();

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

app.get('/', (req, res) => {
res.sendFile(join(__dirname, './views/index.html'));
});

app.get('/status/ping', (req, res) => {
res.send({ msg: 'pong' }).status(200);
});

app.use(cors({ optionsSuccessStatus: 200 }));
app.get('/latest', (req, res, next) => {
fetch('https://forum.freecodecamp.org/latest.json')
.then(response => response.json())
.then(data => {
res.json(data);
})
.catch(err => next(err));
});

app.use((req, res) => res.status(404).send('not found'));

app.use((err, req, res) => res.status(500).json(err));

const portNum = process.env.PORT || 3000;

app.listen(portNum, function () {
console.log(`Your app is listening on port ${portNum}`);
});

export default app;

0 comments on commit a1c5406

Please sign in to comment.