-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from NYPL-discovery/lambda
Lambda
- Loading branch information
Showing
10 changed files
with
955 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,54 @@ | ||
var cluster = require('cluster') | ||
const config = require('config'); | ||
const log = require('loglevel'); | ||
const swaggerDocs = require('./swagger.v0.2.json'); | ||
const pjson = require('./package.json'); | ||
|
||
const config = require('config') | ||
const log = require('loglevel') | ||
require('dotenv').config(); | ||
|
||
log.setLevel(config.get('loglevel')) | ||
var express = require('express'); | ||
var elasticsearch = require('elasticsearch'); | ||
|
||
if (cluster.isMaster) { | ||
// var numCPUs = require('os').cpus().length | ||
var app = express(); | ||
|
||
for (var i = 0; i < 1; i++) { | ||
cluster.fork() | ||
} | ||
app.thesaurus = config.thesaurus; | ||
|
||
cluster.on('exit', function () { | ||
console.log('A worker process died, restarting...') | ||
cluster.fork() | ||
}) | ||
} else { | ||
var express = require('express') | ||
var elasticsearch = require('elasticsearch') | ||
var pjson = require('./package.json') | ||
require('./lib/agents')(app); | ||
require('./lib/resources')(app); | ||
|
||
var app = express() | ||
// routes | ||
require('./routes/agents')(app); | ||
require('./routes/resources')(app); | ||
require('./routes/misc')(app); | ||
|
||
app.thesaurus = config.thesaurus | ||
app.esClient = new elasticsearch.Client({ | ||
host: config['elasticsearch'].host | ||
}); | ||
|
||
require('./lib/agents')(app) | ||
require('./lib/resources')(app) | ||
app.all('*', function (req, res, next) { | ||
res.header('Access-Control-Allow-Origin', '*'); | ||
res.header('Access-Control-Allow-Methods', 'GET, OPTIONS'); | ||
res.header('Access-Control-Allow-Headers', 'Content-Type'); | ||
next(); | ||
}); | ||
|
||
// routes | ||
require('./routes/agents')(app) | ||
require('./routes/resources')(app) | ||
require('./routes/misc')(app) | ||
app.get('/', function (req, res) { | ||
res.send(pjson.version) | ||
}); | ||
|
||
app.esClient = new elasticsearch.Client({ | ||
host: config['elasticsearch'].host | ||
}) | ||
// Just testing route | ||
app.get('/api/v0.1/discovery', function (req, res) { | ||
res.send(pjson.version) | ||
}); | ||
|
||
app.all('*', function (req, res, next) { | ||
res.header('Access-Control-Allow-Origin', '*') | ||
res.header('Access-Control-Allow-Methods', 'GET, OPTIONS') | ||
res.header('Access-Control-Allow-Headers', 'Content-Type') | ||
next() | ||
}) | ||
app.get('/api/v0.1/discovery/swagger', function (req, res) { | ||
res.send(swaggerDocs); | ||
}); | ||
|
||
app.get('/', function (req, res) { | ||
res.send(pjson.version) | ||
}) | ||
|
||
require('./lib/globals')(app).then((app) => { | ||
app.listen(config['port'], function () { | ||
console.log('Server started on port ' + config['port']) | ||
}) | ||
}) | ||
} | ||
// Could be removed for the Lambda but necessary for locally running the app. | ||
require('./lib/globals')(app).then((app) => { | ||
app.listen(config['port'], function () { | ||
console.log('Server started on port ' + config['port']); | ||
}); | ||
}); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
const awsServerlessExpress = require('aws-serverless-express'); | ||
const app = require('./app'); | ||
const server = awsServerlessExpress.createServer(app); | ||
|
||
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.