-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
19 lines (16 loc) · 699 Bytes
/
Copy pathindex.js
File metadata and controls
19 lines (16 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'use strict';
const settings = require('ep_etherpad-lite/node/utils/Settings');
const { getUser } = require('./lib/user');
// Config (settings.json -> "ep_current_user": { ... }). All optional.
// path : URL of the endpoint (default "/whoami")
const cfg = settings.ep_current_user || {};
const path = String(cfg.path || '/whoami').replace(/\/+$/, '');
exports.expressCreateServer = (hookName, context) => {
// GET /whoami -> { displayName, sub } (404 when nobody is logged in)
context.app.get(path, (req, res) => {
const user = getUser(req);
if (!user) return res.status(404).json({ error: 'not logged in' });
res.set('Cache-Control', 'no-store');
res.json(user);
});
};