forked from inaturalist/iNaturalistAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (41 loc) · 1.45 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
const fs = require( "fs" );
const path = require( "path" );
const Logstasher = require( "./lib/logstasher" );
// NewRelic is stats module, which needs newrelic.js in the app root
// do as little as possible before loading NewRelic
const newrelicPath = path.join( path.dirname( fs.realpathSync( __filename ) ), "newrelic.js" );
if ( fs.existsSync( newrelicPath ) ) {
require( "newrelic" ); // eslint-disable-line global-require
}
const InaturalistAPI = require( "./lib/inaturalist_api" );
const InaturalistAPIV2 = require( "./lib/inaturalist_api_v2" );
const PORT = Number( process.env.PORT || 4000 );
const main = async ( ) => {
const logstashPath = path.join(
path.dirname( fs.realpathSync( __filename ) ), "./log", `inaturalist_api.${PORT}.log`
);
Logstasher.setLogStreamFilePath( logstashPath );
// prepare the v1 API
const app = await InaturalistAPI.server( );
// add on v2 openapi endpoints
// eslint-disable-next-line no-console
console.log( "Initializing APIv2..." );
await InaturalistAPIV2.initializeOpenapi( app );
return app;
};
if ( require.main === module ) {
main( ).then( app => {
app.listen( PORT );
// eslint-disable-next-line no-console
console.log( `Listening on port ${PORT}` );
if ( process.send ) {
process.send( "ready" );
}
} );
if ( process.pid ) {
// eslint-disable-next-line no-console
console.log( `This process is your pid: ${process.pid}` );
}
} else {
module.exports = main;
}