diff options
| author | pack <pack@packgekko.xyz> | 2026-08-12 17:06:50 +0000 |
|---|---|---|
| committer | pack <pack@packgekko.xyz> | 2026-08-12 17:06:50 +0000 |
| commit | 5611527e313c4add16c432e5cf9d55a987558c02 (patch) | |
| tree | 59ad054325096b6305277b94982bbe7f7f585f59 /server.js | |
| parent | d3adc16a08d95d6e331de55d7d3bf05a66a874a8 (diff) | |
| download | crud-5611527e313c4add16c432e5cf9d55a987558c02.tar.gz | |
final commit
Diffstat (limited to 'server.js')
| -rw-r--r-- | server.js | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -1,19 +1,21 @@ const express = require('express'); const session = require('express-session'); +const requireAuth = require('./middleware/auth'); + const app = express(); -app.use(express.urlencoded({ extended: true })); app.use(express.json()); +app.use(express.static('public')); + app.use(session({ - secret: 'change-this-secret', + secret: 'zxcv1234', resave: false, - saveUninitialized: false + saveUninitialized: false, + cookie: { maxAge: 1000 * 60 * 60 * 24 } /* 1 day. */ })); -const authRoutes = require('./routes/auth'); -const taskRoutes = require('./routes/tasks'); - -app.use('/auth', authRoutes); -app.use('/tasks', taskRoutes); +app.use('/auth', require('./routes/auth')); +app.use('/tasks', requireAuth, require('./routes/tasks')); /* protect task routes. */ -app.listen(3000, () => console.log('running on http://localhost:3000')); +const PORT = process.env.PORT || 3000; +app.listen(PORT, () => console.log(`Server running on http://localhost:${PORT}`)); |