25 lines
654 B
TypeScript
25 lines
654 B
TypeScript
// Our API for demos only
|
|
import {fakeDataBase} from './db';
|
|
import {fakeDemoRedisCache} from './cache';
|
|
|
|
// you would use cookies/token etc
|
|
var USER_ID = 'f9d98cf1-1b96-464e-8755-bcc2a5c09077'; // hardcoded as an example
|
|
|
|
// Our API for demos only
|
|
export function serverApi(req, res) {
|
|
let key = USER_ID + '/data.json';
|
|
let cache = fakeDemoRedisCache.get(key);
|
|
if (cache !== undefined) {
|
|
console.log('/data.json Cache Hit');
|
|
return res.json(cache);
|
|
}
|
|
console.log('/data.json Cache Miss');
|
|
|
|
fakeDataBase.get()
|
|
.then(data => {
|
|
fakeDemoRedisCache.set(key, data);
|
|
return data;
|
|
})
|
|
.then(data => res.json(data));
|
|
}
|