UNPKG

1.89 kBJavaScriptView Raw
1'use strict';
2
3import Server from '../src';
4
5const staticPath = 'http://localhost:7777';
6const server = Server({
7 debug: true,
8 isTOTP: true,
9 staticPath,
10 logo: `${staticPath}/logo.png`,
11 favicon: `${staticPath}/logo.png`,
12 mail: {
13 from: 'admin@example.com',
14 name: 'minimal',
15 version: '0.1.0',
16 send: (mail, callback) => {
17 const input = mail.message.createReadStream();
18 const chunks = [];
19 input.on('data', (chunk) => {
20 chunks.push(chunk);
21 });
22 input.on('end', () => {
23 const data = Buffer.concat(chunks).toString();
24 console.log(data);
25 callback(null, true);
26 });
27 }
28 }
29});
30
31/** Start **/
32if (!module.parent) {
33 const port = 8888;
34 // init
35 async function init() {
36 const {
37 sync, User, Client, DicRole
38 } = server.orm.database();
39 await sync({
40 force: true
41 });
42 await User.add({
43 id: 10001,
44 password: 'nick',
45 email: 'nick@example.com',
46 totp_key: '1234',
47 is_admin: true
48 });
49 await User.add({
50 id: 10002,
51 password: 'ken',
52 email: 'ken@example.com',
53 totp_key: '1234',
54 is_admin: true
55 });
56 await Client.create({
57 id: '740a1d6d-9df8-4552-a97a-5704681b8039',
58 name: 'local',
59 secret: '12345678',
60 redirect_uri: 'http://localhost:8080'
61 });
62 await Client.create({
63 id: 'bd0e56c1-8f02-49f3-b502-129da70b6f09',
64 name: 'test',
65 secret: '12345678',
66 redirect_uri: 'http://localhost:9090'
67 });
68 await DicRole.create({
69 name: 'user',
70 description: 'Normal user'
71 });
72 await DicRole.create({
73 name: 'document',
74 description: 'Document department'
75 });
76 }
77
78 init().then(() => {
79 server.listen(port);
80 console.log('\nInit database done.');
81 console.log(`\nRunning site at:\x1B[36m http://127.0.0.1:${port}\x1B[39m`);
82 });
83}