Skip to content

Commit

Permalink
Database & Caching
Browse files Browse the repository at this point in the history
  • Loading branch information
engineerchirag committed Jan 18, 2024
1 parent df1fba5 commit 2033829
Show file tree
Hide file tree
Showing 66 changed files with 15,380 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Databases&Caching/cookieStorage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');

const app = express();
const PORT = process.env.PORT || 3010;

app.use(express.static('public'));
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());

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

app.get('/logout', (req, res) => {
res.setHeader('Clear-Site-Data', '"cache", "cookies", "storage"')
res.redirect('/');
})

app.post('/set-preferences', (req, res) => {
const preferences = req.body.preferences;
res.cookie('userPreferences', preferences, { maxAge: 3600000 }); // Cookie expires in 1 hour
res.redirect('/');
});

app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
Loading

0 comments on commit 2033829

Please sign in to comment.