-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/refactor server #289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const momentToLong = require('./moment-to-long'); | ||
|
||
module.exports = { | ||
momentToLong, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const Long = require('long'); | ||
|
||
const momentToLong = m => Long.fromValue(m.unix()).mul(1000000000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
module.exports = momentToLong; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,23 @@ | |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const path = require('path'), | ||
Koa = require('koa'), | ||
bodyparser = require('koa-bodyparser'), | ||
send = require('koa-send'), | ||
staticRoot = path.join(__dirname, '../dist'), | ||
app = new Koa(), | ||
router = require('./routes'); | ||
const path = require('path'); | ||
const Koa = require('koa'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be lowecase like the rest of consts here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'll update. casing ultimately has no difference in javascript but its good to keep to convention. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the code more closely, the code actually calls You can look at this convention here: |
||
const koaBodyparser = require('koa-bodyparser'); | ||
const koaCompress = require('koa-compress'); | ||
const koaSend = require('koa-send'); | ||
const koaStatic = require('koa-static'); | ||
const koaWebpack = require('koa-webpack'); | ||
const webpack = require('webpack'); | ||
|
||
app.webpackConfig = require('../webpack.config'); | ||
const webpackConfig = require('../webpack.config'); | ||
const tchannelClient = require('./middleware/tchannel-client'); | ||
const router = require('./router'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
const staticRoot = path.join(__dirname, '../dist'); | ||
const app = new Koa(); | ||
|
||
app.webpackConfig = webpackConfig; | ||
|
||
app.init = function(options) { | ||
options = options || {}; | ||
|
@@ -37,14 +45,10 @@ app.init = function(options) { | |
? options.useWebpack | ||
: process.env.NODE_ENV !== 'production'; | ||
|
||
let koaWebpack; | ||
let compiler; | ||
|
||
if (useWebpack) { | ||
const Webpack = require('webpack'); | ||
|
||
koaWebpack = require('koa-webpack'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
compiler = Webpack(app.webpackConfig); | ||
compiler = webpack(app.webpackConfig); | ||
} | ||
|
||
app | ||
|
@@ -63,21 +67,21 @@ app.init = function(options) { | |
ctx.body = { message: err.message }; | ||
} | ||
}) | ||
.use(bodyparser()) | ||
.use(koaBodyparser()) | ||
.use( | ||
require('koa-compress')({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
koaCompress({ | ||
filter: contentType => !contentType.startsWith('text/event-stream'), | ||
}) | ||
) | ||
.use(require('./middleware/tchannel-client')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.use(tchannelClient) | ||
.use( | ||
useWebpack | ||
? koaWebpack({ | ||
compiler, | ||
dev: { stats: { colors: true } }, | ||
hot: { port: process.env.TEST_RUN ? 8082 : 8081 }, | ||
}) | ||
: require('koa-static')(staticRoot) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
: koaStatic(staticRoot) | ||
) | ||
.use(router.routes()) | ||
.use(router.allowedMethods()) | ||
|
@@ -97,7 +101,7 @@ app.init = function(options) { | |
ctx.set('content-type', 'text/html'); | ||
ctx.body = compiler.outputFileSystem.readFileSync(filename); | ||
} else { | ||
await send(ctx, 'index.html', { root: staticRoot }); | ||
await koaSend(ctx, 'index.html', { root: staticRoot }); | ||
} | ||
} catch (err) { | ||
if (err.status !== 404) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.