-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathserver.ts
135 lines (109 loc) · 3.32 KB
/
server.ts
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// noinspection ES6PreferShortImport
import { cloudInit } from '@cloud/main';
/**
*
*
*
*
*/
const express = require('express');
const http = require('http');
import { Server } from 'http';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { ParseServer } from 'parse-server';
import { Money } from 'ts-money';
import userConfig from '../config/config';
// Load environment dependent configuration
//const env = config.get('env');
import defaultConfig from '../config/config.defaults';
import { ProviderConfigInterface } from './cloud/DataProviders/providers';
import config from './config';
import { schemas } from './Migrations/schemas';
import { MoneyUtils } from '@goplan-finance/utils';
console.log(MoneyUtils);
config.load({
...defaultConfig,
...userConfig,
});
// Perform validation
config.validate({ allowed: 'strict' });
// @todo, ok ok :)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
global.weHateGlobals_dataProviders = config.get('dataProviders') as ProviderConfigInterface[];
process.env.TZ = 'America/New_York'; // here is the magical line
if (!config.get('parse.masterKey')) {
console.error('parse.masterKey not specified');
process.exit(-1);
}
const parseConfig = {
auth: {
google: {
clientId: config.get('parse.auth.google.clientId') as string,
},
},
allowClientClassCreation: false,
databaseURI: config.get('parse.databaseUri'),
cloud: (...aaa: unknown[]) => {
const cloudMain = require('./cloud/main');
cloudMain.cloudInit(config.get('parse.databaseUri'));
},
appId: config.get('parse.appId'),
masterKey: config.get('parse.masterKey') as string,
serverURL: config.get('parse.serverUrl'), // Don't forget to change to https if needed
liveQuery: {
classNames: [
// List of classes to support for query subscriptions
'Watchlist',
'WatchlistItem',
'AssetSymbol',
'AssetProfile',
'Transaction',
'Holding',
'AssetPrice',
'Account',
// '',
// '',
],
},
schema: {
strict: true,
definitions: schemas,
},
};
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey
const app = express();
// Serve static assets from the /public folder
// app.use('/public', express.static(path.join(__dirname, '/public')))
const api = new ParseServer(parseConfig);
// Parse Server plays nicely with the rest of your web routes
// app.get('/', function (req, res) {
// res
// .status(200)
// .send('I dream of being a website. Please star the GoPlan-Finance repo on GitHub!')
// })
function runParse(api: ParseServer, server: Server, port: number, mountPath: string): void {
const httpServer = http.createServer(app);
app.use(mountPath, api);
httpServer.listen(port, function () {
console.log(`GoPlan running on port ${port}.`);
});
// This will enable the Live Query real-time server
ParseServer.createLiveQueryServer(httpServer);
}
const isHTTP = config.get('server.http.enabled');
if (isHTTP) {
runParse(
api,
http.createServer(app),
config.get('server.http.port'),
config.get('server.http.mountPath')
);
}
module.exports = {
app,
config,
};