-
Notifications
You must be signed in to change notification settings - Fork 0
/
userInformationApi.js
76 lines (71 loc) · 4.48 KB
/
userInformationApi.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
const express = require('express');
const routes = require('./routes/routes');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
const db = require('./db/database');
const config = require('./config/env');
const fs = require('fs');
//setting a global path to userInformationApi.js (main file) so it can be used to locate certificates
global.appRoot = path.resolve(__dirname);
if (process.env.NODE_ENV === 'test') {
appRoot += "/test";
}
const server = require('http').createServer(app); //insecure
// const authority = fs.readFileSync(path.normalize(`${global.appRoot}` + '/certificates/SeeChangeCA.crt'), "utf8");
// const certificate = fs.readFileSync(path.normalize(`${global.appRoot}` + '/certificates/SeeChangeCA.crt'), "utf8");
// const privateKey = fs.readFileSync(path.normalize(`${global.appRoot}` + '/certificates/SeeChangeCA.key'), "utf8");
// const credentials = {key: privateKey, cert: certificate, ca: authority};
// const server = require('https').createServer(credentials, app);
app.use(bodyParser.json({limit: '50mb'})); //max file size
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
process.env.NODE_ENV !== 'test' ? db.start() : null;
app.use('/api', routes);
app.use("/api/avatars", express.static(__dirname + '/avatars')); //images in avatar directory are accessible directly
server.listen(config.port, () => {
console.log(`Running on port: ${config.port}`);
console.log('\n' +
' :+@@@ \n' +
' #@@@@@@@. \n' +
' @@@@+. ,@. \n' +
' ,@@@` ,@. \n' +
' ;@@, ,@. \n' +
' :@@ ,@. \n' +
' @@ `@` \n' +
' @@` \n' +
' ,@# + \n' +
' @@ @@@ \n' +
' @@ @@`@@ @@# \'@@` @` \n' +
'.@: @@ `@@ @+ #@ :@ .@ @` \n' +
'\'@` @@ : `@@ @@ @@@` @@@ @; . @@@@ #@@# @@@# @@@@ +@@#\n' +
'#@ @@ @@@ `@@ +@@ ;@ \'### #;@: @` @ .@ @ `@ @ @ @ @\n' +
'#@ @@ @@@ `@@ , +@+@++\'@#++;@\' \'`@` @ @\',@ @ `@ @ @ @+++\n' +
'\'@` @@ : `@@ @#.@#`@,;.:@.+`,@,\'@ @` @ @:+@ @ `@ @;;@ @#.@\n' +
'.@: @@ `@@ ;#; .#\' ,#; .#\' +` + .#.+ + `+ `#,@ \'+`\n' +
' @@ @@`@@ @+@@ \n' +
' @@ @@@ ,. \n' +
' ,@# + \n' +
' @@` \n' +
' @@ `@` \n' +
' :@@ ,@. \n' +
' ;@@, ,@. \n' +
' ,@@@` ,@. \n' +
' @@@@+. ,@. \n' +
' #@@@@@@@. \n' +
' :+@@@ \n' +
'\n')
});
module.exports = server;