-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhome.ts
More file actions
37 lines (29 loc) · 896 Bytes
/
Copy pathhome.ts
File metadata and controls
37 lines (29 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Client } from '@elastic/elasticsearch';
import { Request, Response } from 'express';
import logger from '../logger.ts';
class HomeController {
async index(req: Request, res: Response) {
if (!req.session || !req.session.user) {
return res.render('home/index');
}
const client = new Client(
{
node: process.env.ELASTIC_ENDPOINT,
auth: {
bearer: req.session.user.access_token,
}
}
);
const authenticateResponse = await client.info()
return res.render('home/index', { data: JSON.stringify(authenticateResponse, null, 2) });
}
async logout(req: Request, res: Response) {
req.session.destroy((err) => {
if (err) {
logger.error(`${this.constructor.name}: unable to destroy session:`, { error: err });
}
return res.redirect('/');
});
}
}
export default HomeController;