-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
112 lines (94 loc) · 2.91 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const axios = require('axios')
const got = require('got');
const expressSession = require('express-session')
const passport = require('passport');
const auth0Strategy = require('passport-auth0');
const util = require('util')
const { spawn } = require('child_process')
require("dotenv").config();
// const { RESTClient } = require('cw-sdk-node')
const utils = require('./utils/utils');
const apiRoutes = require('./routes/api')
const authRoutes = require('./routes/auth')
const app = express();
const port = process.env.PORT || 5000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const session = {
secret: process.env.SESSION_SECRET,
cookie: {},
resave: false,
saveUninitialized: false
}
if (app.get("env") === "production") {
// Serve secure cookies, requiring HTTPS
session.cookie.secure = true;
}
const strategy = new auth0Strategy(
{
domain: process.env.AUTH0_DOMAIN,
clientID: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
callbackURL: process.env.AUTH0_CALLBACK_URL
},
function(accessToken, refreshToken, extraParams, profile, done) {
/**
* Access tokens are used to authorize users to an API
* (resource server)
* accessToken is the token to call the Auth0 API
* or a secured third-party API
* extraParams.id_token has the JSON Web Token
* profile has all the information from the user
*/
return done(null, profile);
}
)
// setImmediatePromise(setTimeout(()=>5, 8000)).then((val) => {console.log('scanning done!: ' + val)})
// async function runJobs(){
// let theval = await setImmediatePromise(analyzeMarket('btc'))
// console.log('Initial scan finished!: ' + theval)
// setInterval(console.log, 2000, 'ada')
// }
// runJobs()
setImmediate(() => {
const child = spawn('node', ['jobs/scan.js'])
child.stdout.on('data', data => {
console.log(`stdout:\n${data}`);
});
child.stderr.on('data', data => {
console.error(`stderr: ${data}`);
});
child.on('error', (error) => {
console.error(`error: ${error.message}`);
});
child.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
})
app.use(express.static(path.join(__dirname, "client", "build")))
app.use(expressSession(session))
/*
* Initialize passport below
*/
passport.use(strategy)
app.use(passport.initialize())
app.use(passport.session())
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((user, done) => {
done(null, user);
});
app.use((req, res, next) => {
res.locals.isAuthenticated = req.isAuthenticated()
next()
})
app.use('/', authRoutes)
app.use('/api', apiRoutes)
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'client', 'build','index.html'))
});
app.listen(port, () => console.log(`Listening on port ${port}`));