-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
58 lines (50 loc) · 1.23 KB
/
Copy pathapp.js
File metadata and controls
58 lines (50 loc) · 1.23 KB
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
'use strict';
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
const jwt = require('jsonwebtoken');
app.db = dynamo;
app.use(bodyParser.json());
// middlewares add
app.use('/api', require('./middlewares/auth'));
// app controllers
app.use('/', require('./routes'));
app.get('/s', function(req, res) {
app.db.scan({TableName: 'users'}, function(err, body) {
if (err) {
res.send(err);
return;
}
res.send(JSON.stringify(body));
});
});
app.get('/api/:table', function(req, res) {
app.db.scan({TableName: 'users'}, function(err, body) {
if (err) {
res.send(err);
return;
}
res.send(JSON.stringify(body));
});
});
app.get('/', function(req, res) {
app.db.scan({TableName: 'users'}, function(err, body) {
if (err) {
res.send(err);
return;
}
let token = jwt.sign(body, 'q7w8e9r7', {
expiresIn: 24 * 60 * 60, // expires in 24 hours
});
// return the information including token as JSON
console.log(body);
res.json({
code: 0,
status: 'Enjoy your token!',
token: token,
});
});
});
module.exports = app;