-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
24 lines (22 loc) · 644 Bytes
/
app.js
File metadata and controls
24 lines (22 loc) · 644 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const Koa = require('koa');
const MangoDB = require('./services/MangoDB');
const S3Storage = require('./services/S3Storage')
const app = new Koa();
const mangodb = new MangoDB("fake_users.json");
app.use(async (ctx, next) => {
if (ctx.path === '/users/mongodb') {
await mangodb.connect();
const latestRecord = await mangodb.getLatestRecord();
await mangodb.close();
ctx.body = latestRecord;
}
else {
ctx.throw(404, `Not Found: ${ctx.path}`);
}
await next();
});
// start the server
const port = 3000;
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});