*.js: WIP changes for session handling, but ...
Some checks failed
Basic Checking / Explore-Gitea-Actions (push) Failing after 42s
Some checks failed
Basic Checking / Explore-Gitea-Actions (push) Failing after 42s
/newSession is still not right. It seems to work right the first time, but then is an error... Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
b41568337b
commit
523b979764
3 changed files with 23 additions and 36 deletions
35
app.js
35
app.js
|
@ -38,16 +38,21 @@ const db = new sqlite3.Database(config.db_path, (err) => {
|
|||
}
|
||||
})
|
||||
|
||||
const accessLogStream = fs.createWriteStream(
|
||||
path.join(__dirname, 'log', 'access.log'),
|
||||
{ flags: 'a' }
|
||||
)
|
||||
if (config.PRODUCTION) {
|
||||
let accessLogStream = fs.createWriteStream(
|
||||
path.join(__dirname, 'log', 'access.log'),
|
||||
{ flags: 'a' }
|
||||
)
|
||||
app.use(morgan('combined', { stream: accessLogStream }))
|
||||
} else {
|
||||
app.use(morgan('combined'))
|
||||
}
|
||||
|
||||
app.use(bodyParser.json())
|
||||
app.use(morgan('combined', { stream: accessLogStream }))
|
||||
app.use(session({
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
cookie: { maxAge: 3600000 },
|
||||
secret: config.session_token
|
||||
}))
|
||||
|
||||
|
@ -84,12 +89,6 @@ try {
|
|||
|
||||
// Serve the HTML file
|
||||
app.get('/', (req, res) => {
|
||||
if (typeof req.session.cookie.expires === 'undefined') {
|
||||
const hour = 3600000
|
||||
req.session.cookie.expires = new Date(Date.now() + hour)
|
||||
req.session.cookie.maxAge = hour
|
||||
}
|
||||
|
||||
res.sendFile(path.join(__dirname, 'index.html'))
|
||||
})
|
||||
app.get('/asset/frontend.js', (req, res) => {
|
||||
|
@ -97,9 +96,13 @@ app.get('/asset/frontend.js', (req, res) => {
|
|||
})
|
||||
|
||||
app.get('/newSession', (req, res) => {
|
||||
log.info(req.session)
|
||||
req.session.regenerate()
|
||||
log.info(req.session)
|
||||
log.info(req.session.id)
|
||||
req.session.regenerate((error) => {
|
||||
if (error) {
|
||||
log.error(error)
|
||||
}
|
||||
})
|
||||
log.info(req.session.id)
|
||||
})
|
||||
|
||||
// Route to get a random animal name
|
||||
|
@ -120,12 +123,10 @@ app.post('/recordButtonClick', (req, res) => {
|
|||
try {
|
||||
// const { buttonName, sessionId } = req.body;
|
||||
const result = req.body
|
||||
log.error(result)
|
||||
|
||||
db.run(
|
||||
'INSERT INTO button_clicks (session_id, animal_name, button_name, timestamp, time_difference) VALUES (?, ?, ?, ?, ?)',
|
||||
[
|
||||
result.session,
|
||||
req.session.id,
|
||||
result.animal,
|
||||
result.button,
|
||||
result.time,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue