-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds babel and starts adding flow to the code base
This is a huge move of everything though it's not a change at all to the API. Starts to reorganize the code in a bit more logical way as well.
- Loading branch information
Daniel Sellers
committed
Dec 9, 2017
1 parent
8cd66e4
commit cfb3643
Showing
200 changed files
with
6,782 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["flow"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[ignore] | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[lints] | ||
|
||
[options] | ||
|
||
[strict] |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
const test = require('ava'), | ||
servers = [], | ||
events = require('harken'), | ||
http2 = require('http2'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
semver = require('semver'), | ||
configStore = require('./utils/config'); | ||
|
||
test.beforeEach(() => { | ||
configStore.reset(); | ||
}); | ||
|
||
test.afterEach(() => { | ||
const shutDownEvents = events.required(['complete'], () => { | ||
// t.end(); | ||
}); | ||
|
||
servers.forEach((server, i) => { | ||
shutDownEvents.add(`server:${i}`); | ||
server.close(() => { | ||
events.emit(`server:${i}`); | ||
}); | ||
}); | ||
|
||
events.emit('complete'); | ||
}); | ||
|
||
test.cb('should return an http2 server when http2 and correct params are passed in', t => { | ||
const http2App = require('./index'); | ||
|
||
http2App.server({ | ||
routeJSONPath: './test_stubs/routes_stub.json', | ||
templatePath: './test_stubs/templates', | ||
routePath: './test_stubs', | ||
compress: false, | ||
server: http2, | ||
port: 9996, | ||
serverOptions: { | ||
cert: fs.readFileSync(path.join(__dirname, './test_stubs/certs/test.crt')), | ||
key: fs.readFileSync(path.join(__dirname, './test_stubs/certs/tests.key')) | ||
}, | ||
log: { | ||
log: () => {} | ||
} | ||
}); | ||
|
||
http2App.events.once('server:started', settings => { | ||
servers.push(settings.server); | ||
|
||
if (semver.lt(process.versions.node, '8.8.0')) { | ||
t.true(settings.server instanceof http2.Server); | ||
} else { | ||
t.is(settings.server.constructor.name, 'Http2Server'); | ||
} | ||
|
||
t.end(); | ||
}); | ||
}); |
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,46 @@ | ||
'use strict'; | ||
|
||
const events = require('harken'), | ||
pkg = require('./package.json'), | ||
parser = require('./utils/parser'), | ||
webSockets = require('./web-sockets'), | ||
uuid = require('uuid'), | ||
config = require('./utils/config'), | ||
setup = require('./utils').setup, | ||
routeStore = require('./routes/routeStore'), | ||
wrapper = configIn => { | ||
const configObj = config.set(configIn), | ||
logger = configObj.log, | ||
routes = require(configObj.routeJSONPath); | ||
|
||
// take care of any setup tasks before starting the server | ||
events.once('setup:complete', () => { | ||
const server = require('./routes/index').server(configObj.server, routes, configObj); | ||
|
||
server.listen(configObj.port); | ||
|
||
if (configIn.webSockets !== false) { | ||
// enables websockets for data requests | ||
webSockets(server, configIn.webSockets); | ||
} | ||
|
||
logger.info(`monument v${pkg.version} up and running on port: ${configObj.port}`); | ||
events.emit('server:started', { | ||
version: pkg.version, | ||
port: configObj.port, | ||
server: server | ||
}); | ||
}); | ||
|
||
setup(configObj); | ||
}; | ||
|
||
module.exports = { | ||
server: wrapper, | ||
events: events, | ||
parser: parser, | ||
routes: routeStore, | ||
createUUID: () => { | ||
return uuid.v4(); | ||
} | ||
}; |
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,55 @@ | ||
'use strict'; | ||
|
||
const test = require('ava'), | ||
servers = [], | ||
events = require('harken'), | ||
spdy = require('spdy'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
configStore = require('./utils/config'); | ||
|
||
test.beforeEach(() => { | ||
configStore.reset(); | ||
}); | ||
|
||
test.afterEach(() => { | ||
const shutDownEvents = events.required(['complete'], () => { | ||
// t.end(); | ||
}); | ||
|
||
servers.forEach((server, i) => { | ||
shutDownEvents.add(`server:${i}`); | ||
server.close(() => { | ||
events.emit(`server:${i}`); | ||
}); | ||
}); | ||
|
||
events.emit('complete'); | ||
}); | ||
|
||
test.cb('should return an spdy server when spdy and correct params are passed in', t => { | ||
const spdyApp = require('./index'); | ||
|
||
spdyApp.server({ | ||
routeJSONPath: './test_stubs/routes_stub.json', | ||
templatePath: './test_stubs/templates', | ||
routePath: './test_stubs', | ||
compress: false, | ||
server: spdy, | ||
port: 9995, | ||
serverOptions: { | ||
cert: fs.readFileSync(path.join(__dirname, './test_stubs/certs/test.crt')), | ||
key: fs.readFileSync(path.join(__dirname, './test_stubs/certs/tests.key')), | ||
ca: fs.readFileSync(path.join(__dirname, './test_stubs/certs/rootCA.key')) | ||
}, | ||
log: { | ||
log: () => {} | ||
} | ||
}); | ||
|
||
spdyApp.events.once('server:started', settings => { | ||
servers.push(settings.server); | ||
t.true(settings.server instanceof spdy.Server); | ||
t.end(); | ||
}); | ||
}); |
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,111 @@ | ||
'use strict'; | ||
|
||
const test = require('ava'), | ||
app = require('./index'), | ||
http = require('http'), | ||
servers = [], | ||
events = require('harken'), | ||
configStore = require('./utils/config'); | ||
|
||
test.beforeEach(() => { | ||
configStore.reset(); | ||
}); | ||
|
||
test.afterEach(() => { | ||
const shutDownEvents = events.required(['complete'], () => { | ||
// t.end(); | ||
}); | ||
|
||
servers.forEach((server, i) => { | ||
shutDownEvents.add(`server:${i}`); | ||
server.close(() => { | ||
events.emit(`server:${i}`); | ||
}); | ||
}); | ||
|
||
events.emit('complete'); | ||
}); | ||
|
||
test('should be correctly defined', t => { | ||
t.is(typeof app.server, 'function'); | ||
t.is(typeof app.parser, 'function'); | ||
t.is(typeof app.routes, 'object'); | ||
t.is(typeof app.events, 'object'); | ||
}); | ||
|
||
test('should have a parser method', t => { | ||
t.is(typeof app.parser, 'function'); | ||
}); | ||
|
||
test.cb('should return a server when run', t => { | ||
app.server({ | ||
routeJSONPath: './test_stubs/routes_stub.json', | ||
routePath: './test_stubs', | ||
templatePath: './test_stubs/templates', | ||
port: 9999, | ||
log: { | ||
log: () => {} | ||
} | ||
}); | ||
|
||
app.events.once('server:started', settings => { | ||
servers.push(settings.server); | ||
t.true(settings.server instanceof http.Server); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test.cb('should return a server when run and no port passed in', t => { | ||
const noPortApp = require('./index'); | ||
|
||
noPortApp.server({ | ||
routeJSONPath: './test_stubs/routes_stub.json', | ||
templatePath: './test_stubs/templates', | ||
routePath: './test_stubs', | ||
port: 9998, | ||
log: { | ||
log: () => {} | ||
} | ||
}); | ||
|
||
noPortApp.events.once('server:started', settings => { | ||
servers.push(settings.server); | ||
t.true(settings.server instanceof http.Server); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test.cb('should return a server when run and compress passed in', t => { | ||
const compressApp = require('./index'); | ||
|
||
compressApp.server({ | ||
routeJSONPath: './test_stubs/routes_stub.json', | ||
templatePath: './test_stubs/templates', | ||
compress: false, | ||
routePath: './test_stubs', | ||
port: 9997, | ||
log: { | ||
log: () => {} | ||
} | ||
}); | ||
|
||
compressApp.events.once('server:started', settings => { | ||
servers.push(settings.server); | ||
t.true(settings.server instanceof http.Server); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('should have a createUUID function', t => { | ||
t.is(typeof app.createUUID, 'function'); | ||
}); | ||
|
||
test('should return a uuid when called', t => { | ||
const regex = /[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i; | ||
|
||
t.true(regex.test(app.createUUID())); | ||
}); | ||
|
||
test('should not return the same uuid when called multiple times', t => { | ||
t.not(app.createUUID(), app.createUUID()); | ||
}); |
Oops, something went wrong.