Skip to content
Snippets Groups Projects
Commit 7024e4e0 authored by Ulf Seltmann's avatar Ulf Seltmann
Browse files

added simple register endpoint

parent 48e52ce0
Branches
Tags
No related merge requests found
......@@ -39,7 +39,7 @@ class Register {
};
});
fs.writeFileSync(path.resolve(this.storage, this.name), JSON.stringify(data), { encoding: 'utf8', flag: 'w' });
debug('register ${this.name} saved to ${this.storage}');
debug(`register "${this.name}" saved to "${this.storage}"`);
};
this.restore = () => __awaiter(this, void 0, void 0, function* () {
const data = JSON.parse(fs.readFileSync(path.resolve(this.storage, this.name), { encoding: 'utf8' }));
......@@ -47,7 +47,7 @@ class Register {
this.cacheRegister[cache.name] = new Cache();
this.cacheRegister[cache.name].fromObject(cache.data);
});
debug('register ${this.name} restored from ${this.storage}');
debug(`register "${this.name}" restored from "${this.storage}"`);
});
fs.existsSync(storage) || fs.mkdirSync(storage);
}
......
......@@ -12,12 +12,18 @@ const storagePath = process.env.DATA_DIR || path.resolve(process.cwd(), 'data');
const register = new cache.Register(storagePath, 'apis');
register.restore();
app.use(compression());
app.get('/admin/add/:registerName', (req, res, next) => {
if (!req.query.url)
return res.status(400).send(`you need to specify an url (e.g. ${req.url}?url=http://example.com)`);
register.add(req.params.registerName, req.query.url);
res.send(`added ${req.params.registerName} with URL "${req.query.url}"`);
});
app.get('/admin/list/register/:registerName', (req, res, next) => {
});
app.use(cache.Middleware(register));
const server = app.listen(3000, () => {
debug('server up and running');
});
app.get('/admin/add/:registerName', (req, res, next) => {
});
process.stdin.resume();
process.on('SIGTERM', () => {
register.save();
......
......@@ -42,7 +42,7 @@ export class Register {
});
fs.writeFileSync(path.resolve(this.storage, this.name), JSON.stringify(data), {encoding: 'utf8', flag: 'w'});
debug('register ${this.name} saved to ${this.storage}');
debug(`register "${this.name}" saved to "${this.storage}"`);
}
restore = async (): Promise<void> => {
......@@ -52,7 +52,7 @@ export class Register {
this.cacheRegister[cache.name] = new Cache();
this.cacheRegister[cache.name].fromObject(cache.data);
});
debug('register ${this.name} restored from ${this.storage}');
debug(`register "${this.name}" restored from "${this.storage}"`);
}
}
......
......@@ -14,16 +14,22 @@ const register = new cache.Register(storagePath, 'apis');
register.restore();
app.use(compression());
app.use(cache.Middleware(register));
const server = app.listen(3000, () => {
debug('server up and running');
app.get('/admin/add/:registerName', (req, res, next) => {
if (!req.query.url) return res.status(400).send(`you need to specify an url (e.g. ${req.url}?url=http://example.com)`);
register.add(req.params.registerName, req.query.url);
res.send(`added ${req.params.registerName} with URL "${req.query.url}"`)
});
app.get('/admin/add/:registerName', (req, res, next) => {
app.get('/admin/list/register/:registerName', (req, res, next) => {
});
})
app.use(cache.Middleware(register));
const server = app.listen(3000, () => {
debug('server up and running');
});
process.stdin.resume();
process.on('SIGTERM', () => {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment