-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
67 lines (58 loc) · 2.18 KB
/
server.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
63
64
65
66
67
#!/usr/bin/env nodejs
const dotenv = require('dotenv').load()
const express = require('express')
const cors = require('cors')
const helmet = require('helmet')
const pino = require('pino')
const app = express()
// var bodyParser = require('body-parser')
var methodOverride = require('method-override')
const cloudFunctionRunningService = require('./lib/cloudFunctionData/cloudFunctionRunningService')
const sentiCloudFunctionRunning = new cloudFunctionRunningService()
module.exports.sentiCloudFunctionRunning = sentiCloudFunctionRunning
module.exports.logger = console
// const logger=pino(pino.destination(`/var/log/nodejs/cloudfunctions/${new Date().toLocaleDateString().replace(/\//g, '-')}.json`))
// module.exports.logger = pino(pino.extreme(`/var/log/nodejs/cloudfunctions/${new Date().toLocaleDateString().replace(/\//g, '-')}-others.json`))
// const expressPino = require('express-pino-logger')({
// logger: logger
// })
// app.use(expressPino)
// API endpoint imports
const port = process.env.NODE_PORT || 3011
app.use(helmet())
// app.use(bodyParser({ }))
// app.use(express.json())
app.use(express.json({ limit: '150mb' }));
app.use(express.urlencoded({ extended: true, limit: '150mb' }))
app.use(cors())
app.use(methodOverride())
const functions = require('./api/functions/functions')
const createFunction = require('./api/crud/createFunction')
const getFunction = require('./api/crud/getFunction')
const getFunctions = require('./api/crud/getFunctions')
const updateFunction = require('./api/crud/updateFunction')
const deleteFunction = require('./api/crud/deleteFunction')
app.use([createFunction, updateFunction, getFunction, getFunctions, deleteFunction, functions])
app.use(function (err, req, res, next) {
res.status(500).json(err)
})
//---Start the express server---------------------------------------------------
const startServer = () => {
app.listen(port, () => {
console.clear()
console.log('Senti Cloud Functions server started on port', port)
console.log(process.version)
}).on('error', (err) => {
if (err.errno === 'EADDRINUSE') {
console.log('Server not started, port ' + port + ' is busy')
} else {
console.log(err)
}
})
}
try {
startServer()
}
catch (e) {
console.log(e)
}