-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-server.ts
62 lines (58 loc) · 1.51 KB
/
test-server.ts
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
53
54
55
56
57
58
59
60
61
62
import http from 'http';
import {Init, type SetupProps,SheetDataReq } from "./src/index";
// yeh, i dont like testing, if it works, it works
const config: SetupProps = {
googleApi:{
rootFolder: './credentials',
fileName: 'credentials.json',
}
}
const tableRequest: Record<string,SheetDataReq> = {
NAMES: {
googleFileId: '1f9ixtL0zNpcclRBYMMUBwu1fJnfm_ckjEIKgIGqG5Xw',
sheetName:'Names',
sheetRange: 'A1:ZZ',
columns:[{
position:0,
name:'id'
},
{
position: 1,
name: 'name'
},
{
position:2,
name:'number'
},
{
position:3,
name:'email'
},
{
position:4,
name: 'noDomain'
},
{
position:5,
name: 'domain'
}
]
}
} as const
async function test(req: http.IncomingMessage, res: http.ServerResponse){
const companion = Init(config);
const promise = companion.spreadSheetServices.useDataFromTable(tableRequest.NAMES as SheetDataReq);
const result = await promise
res.write(JSON.stringify(Array.from(result.response.data)));
res.end();
}
http.createServer(async (req, res) => {
try{
await test(req,res);
}catch(e){
if(e instanceof Error){
res.write(e.message);
}
res.end();
}
}).listen(1634);