-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
62 lines (45 loc) · 1.35 KB
/
app.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
54
55
56
57
58
59
60
61
62
const express = require('express')
const cors = require('cors')
const config = require('./config/config')
const { Client } = require('cassandra-driver');
const helmet = require('helmet')
const app = express()
app.use(express.json())
// logger
const logger = require('winston');
const router = require('./routes/cassandra_router');
port = config.port || 3000
const getObjectFromBucket = require('./controller/oci');
getObjectFromBucket()
.then(() => console.log('Object retrieved successfully'))
.catch(err => console.error(`Failed to retrieve object: ${err}`));
// parses incoming requests with urlencoded payloads and is based on body-parser
app.use(express.urlencoded({ extended: true }))
app.use(cors())
// credintals needed
// require('./database/casandra-config')
// console.log(config)
//routes
app.use('/api',router)
app.use((err, req, res, next) => {
logger.error(`${err.status || 500} - ${err.message} - ${req.originalUrl} - ${req.method} - ${req.ip}`);
next();
})
app.use(helmet())
// Error handling
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ message: err.message });
});
app.get('/', (req, res) => {
return res.status(200).json({
message: "server responding "
})
})
app.listen(port, () => {
console.table([
{
port: `${port}`
}
])
})