Repository navigation
Expand file tree
/
Copy pathmain.ts
More file actions
52 lines (35 loc) 路 1.55 KB
/
Copy pathmain.ts
File metadata and controls
52 lines (35 loc) 路 1.55 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
45
46
47
48
49
50
51
52
import Config from './config/config.json' with { type: 'json' };
import { Schema } from '/lib/data/schema.ts';
import { Locals } from '/lib/data/types.ts';
import { Server } from 'x/http';
import { DB } from '/lib/db.ts';
import { handler as handle_resource_request } from '/lib/routes/resource.ts';
import { handler as handle_status_request } from '/lib/routes/status.ts';
import { handler as handle_signup } from '/lib/routes/sign_up.ts';
import { handler as handle_signin } from '/lib/routes/sign_in.ts';
import { handler as handle_grant } from '/lib/routes/grant.ts';
import { handler as handle_exchange } from '/lib/routes/exchange.ts';
import { handler as handle_refresh } from '/lib/routes/refresh.ts';
import { handler as handle_authorization } from '/lib/routes/authenticate.ts';
import { handler as handle_not_found } from '/lib/routes/not_found.ts';
export const server = new Server<Locals>();
export const db = new DB('./data.json', Schema);
await db.read();
server.use(handle_authorization);
server.get('/status', handle_status_request);
server.get('/resource/:action', handle_resource_request);
// User Authentication
server.post('/sign-up', handle_signup);
server.post('/sign-in', handle_signin);
// Third Party Authentication
server.get('/grant', handle_grant);
server.post('/exchange', handle_exchange);
server.post('/refresh', handle_refresh);
server.use(handle_not_found);
const tls = Config.tls.key.length && Config.tls.cert.length
? { key: Config.tls.key, cert: Config.tls.cert }
: undefined;
server.listen({
port: Config.port,
tls,
});