-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsample.js
53 lines (44 loc) · 1.26 KB
/
sample.js
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
const express = require('express');
require('express-async-errors');
const Redis = require('ioredis');
const path = require('path');
const nadeshiko = require('./dist/lib/nadeshiko');
// TODO modify
const secret = require('./secret/gdrive.json');
const app = express();
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.get('/', (req, res) => {
res.sendFile(path.resolve(__dirname, 'public/index.html'));
});
app.get('/main.js', (req, res) => {
res.sendFile(path.resolve(__dirname, 'public/main.js'));
});
const redis = new Redis(6379, '127.0.0.1');
const prefix = 'nadeshiko-dev';
const sheetID = process.env.SHEET_ID;
app.use('/', nadeshiko.makeRouter({
redis,
metadataSheetId: sheetID,
dataPath: path.resolve(__dirname, 'tmp'),
serviceKey: {
client_email: secret.client_email,
private_key: secret.private_key,
},
prefix,
}));
const port = 3000;
app.listen(port, async () => {
console.log(`listen port=${port}`);
try {
// get data
const table = new nadeshiko.TableCache(redis, prefix);
const ndsk = new nadeshiko.Nadeshiko(redis, prefix);
const key = ndsk.key('foo');
const items = await ndsk.mget('foo');
const item = await ndsk.get('foo', 1);
console.log({ key, items, item });
} catch (err) {
console.error(err);
}
});