-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
44 lines (38 loc) · 1.19 KB
/
example.js
File metadata and controls
44 lines (38 loc) · 1.19 KB
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
38
39
40
41
42
43
44
import express from 'express';
import dotenv from 'dotenv';
dotenv.config({ path: './.env-sample' });
const tokens = process.env.TOKENS.split(',').map(e => {
const parts = e.split(/\s+/);
return {
token: parts[0],
scope: parts.slice(1),
};
});
import fs from 'fs';
import glue from './main.js';
import hold from './adapter.js';
const storagePath = '/storage';
const authPath = '/authorize';
const port = process.env.PORT || 3000;
express()
.use(glue.cors())
.use(glue.webfinger({
storagePath: handle => `${ storagePath }/${ handle }`,
authPath,
}))
.enable('trust proxy')
.get(authPath, (req, res, next) => {
return res.send(fs.readFileSync('./authorize.html', 'utf8').replace('$REDIRECT_URI', req.query.redirect_uri).replace('$ADDRESS', `${ process.env.USERNAME }@${ req.host }`).replace('$TOKENS', JSON.stringify(tokens, null, ' ')));
})
.use(storagePath, express.json(), express.raw({
limit: '1mb',
type: '*/*',
}), glue.remotestorage({
getScope (username, token) {
if (username !== process.env.USERNAME)
return
return tokens.filter(e => e.token === token).shift()?.scope.join(' ');
},
hold,
}))
.listen(port, () => console.info('> Running on port ' + port));