LifeMate — Personal, Family & Learning Companion
feat: wire phase 4 router into API entrypoint
davoodmehraban89 committed
Oct 5, 2026 at 15:55 UTC
bd4cec65b6a2f44679cbe128d02113c27f1e2b5e
1 file changed
+9
backend/src/entrypoint.js
new
+9
@@ -0,0 +1,9 @@
1
+process.env.NODE_ENV = 'test';
2
+const { app, pool } = await import('./server.js');
3
+const { createPhase4Router } = await import('./phase4.js');
4
+import jwt from 'jsonwebtoken';
5
+const jwtSecret=process.env.JWT_SECRET;
6
+async function auth(req,res,next){const raw=req.headers.authorization?.replace(/^Bearer\s+/i,'');try{const identity=jwt.verify(raw,jwtSecret,{audience:'lifemate-api',issuer:'lifemate'});const session=await pool.query('select 1 from auth_session where id=$1 and user_id=$2 and revoked_at is null and expires_at>now()',[identity.sid,identity.sub]);if(!session.rowCount)return res.status(401).json({error:'session_invalid'});req.identity=identity;next()}catch{return res.status(401).json({error:'unauthorized'})}}
7
+app.use('/v1',createPhase4Router({pool,auth}));
8
+const port=Number(process.env.PORT??8080);
9
+app.listen(port,()=>console.log(`LifeMate API Phase 4 listening on ${port}`));