Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add first api tests and new environment
- Loading branch information
Showing
15 changed files
with
242 additions
and
99 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,13 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
if (!require('piping')({ | ||
hook: true, | ||
ignore: /(\/\.|~$|\.json$)/i, | ||
})) { | ||
return; | ||
} | ||
|
||
require('@babel/polyfill/noConflict'); | ||
require('@babel/register')(); | ||
require('../dev.server'); |
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,17 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const isProduction = process.env.NODE_ENV === 'production'; | ||
|
||
if (!isProduction) { | ||
if (!require('piping')({ | ||
hook: true, | ||
ignore: /(\/\.|~$|\.json$)/i, | ||
})) { | ||
return; | ||
} | ||
} | ||
|
||
require('@babel/polyfill/noConflict'); | ||
require('@babel/register')(); | ||
require('../src/server'); |
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,91 @@ | ||
import path from 'path'; | ||
import express from 'express'; | ||
import webpack from 'webpack'; | ||
import webpackDevMiddleware from 'webpack-dev-middleware'; | ||
import webpackHotMiddleware from 'webpack-hot-middleware'; | ||
import httpProxy from 'http-proxy'; | ||
|
||
import webpackConfig from './webpack.config'; | ||
|
||
const devPort = process.env.DEV_PORT || 8080; | ||
const port = process.env.DEV_PORT || 9000; | ||
const app = express(); | ||
const compiler = webpack(webpackConfig); | ||
const make = (apiAddress) => { | ||
const proxy = apiAddress | ||
? httpProxy.createProxyServer({ | ||
target: apiAddress, | ||
}) : httpProxy.createProxyServer(); | ||
|
||
proxy.on('error', (error, req, res) => { | ||
if (error.code !== 'ECONNRESET') { | ||
console.error('proxy error', error); | ||
} | ||
if (!res.headersSent) { | ||
res.writeHead(500, { 'content-type': 'application/json' }); | ||
} | ||
|
||
res.status(500).json({ error: 'proxy_error', reason: error.message }); | ||
}); | ||
|
||
return proxy; | ||
}; | ||
const register = (app, proxy, path, apiAddress) => { | ||
console.log(`Server ${app.name} will proxy ${path} to ${apiAddress}`); | ||
|
||
app.use(path, (req, res) => { | ||
proxy.web(req, res, { | ||
target: apiAddress, | ||
}); | ||
}); | ||
}; | ||
const middleware = [ | ||
webpackDevMiddleware(compiler, { | ||
port: devPort, | ||
contentBase: path.join(__dirname, 'src', 'client'), | ||
hot: true, | ||
stats: { | ||
colors: true, | ||
}, | ||
compress: true, | ||
}), | ||
webpackHotMiddleware(compiler, { | ||
// eslint-disable-next-line no-console | ||
log: console.log, | ||
heartbeat: 2000, | ||
path: '/__webpack_hmr', | ||
}), | ||
]; | ||
|
||
app.use(middleware); | ||
|
||
[ | ||
{ address: `http://localhost:${port}/v1`, path: '/v1' }, | ||
{ address: `http://localhost:${port}/v2`, path: '/v2' }, | ||
].forEach(cfg => { | ||
const proxy = make(cfg.address); | ||
app.on('stop', () => proxy.close()); | ||
register(app, proxy, cfg.path, cfg.address); | ||
}); | ||
|
||
app.get('*', (req, res, next) => { | ||
const filename = path.join(compiler.outputPath, 'index.html'); | ||
compiler.outputFileSystem.readFile(filename, (err, result) => { | ||
if (err) { | ||
return next(err); | ||
} | ||
res.set('content-type', 'text/html'); | ||
res.send(result); | ||
res.end(); | ||
}); | ||
}); | ||
|
||
app.listen(devPort, () => { | ||
console.log('Developer Server | port: %s', devPort); | ||
}); | ||
|
||
process | ||
.on('dev server Uncaught Exception', (err) => { | ||
// eslint-disable-next-line no-console | ||
console.error('<!> Exception %s: ', err.message, err.stack); | ||
}); |
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,2 @@ | ||
require('@babel/polyfill/noConflict'); | ||
require('@babel/register')(); |
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 @@ | ||
const babelConfig = require('./babel.config'); | ||
|
||
module.exports = require('babel-jest').createTransformer(babelConfig); |
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
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.