Skip to content

Commit

Permalink
cache studyweek
Browse files Browse the repository at this point in the history
  • Loading branch information
C4illin committed Nov 20, 2023
1 parent 9aff2bc commit 884aa45
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lasvecka-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ const app = express();
const computeTime = require('./calc_date.js');
const port = process.env.PORT || 3000;

let studyweek = '';
let studyweekNum = '';

function updateStudyWeek() {
studyweek = computeTime();
studyweekNum = studyweek.replace('LV ', '').replace('Självstudier', 'S').replace('Tentavecka', 'T');
return { studyweek, studyweekNum };
}

app.use(express.static('public'));

app.get('/', (req, res) => {
let studyweek = computeTime();
let studyweekNum = studyweek.replace('LV ', '').replace('Självstudier', 'S').replace('Tentavecka', 'T');
// eg. 2023-W45
let week = moment().format('YYYY-[W]WW');
let { studyweek, studyweekNum } = updateStudyWeek();
let week = moment().format('YYYY-[W]WW'); // eg. 2023-W45
let data = { studyweek, week, studyweekNum };
res.send(render(data));
});
Expand Down

0 comments on commit 884aa45

Please sign in to comment.