-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (67 loc) · 3.28 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
if (process.env.NODE_ENV != 'production') {
process.env.NODE_ENV = 'development';
}
let hastemap = require('./hastemap')
hastemap(function(moduleObj) {
require('react-native/setupBabel')()
const path = require('path');
const webpack = require('webpack');
const express = require('express');
let config = require('../../webpack.config');
let configAlias = config.resolve.alias;
config.resolve.alias = Object.assign({},moduleObj,configAlias)
const hotloadmiddleware = require('webpack-hot-middleware');
const liveReloadmiddleware = require('./middleware/liveReloadmiddleware');
const ReactNativeServerMiddlewarePath = 'react-native/local-cli/server/middleware';
const loadRawBodyMiddleware = require(ReactNativeServerMiddlewarePath + '/loadRawBodyMiddleware');
const getDevToolsMiddleware = require(ReactNativeServerMiddlewarePath + '/getDevToolsMiddleware');
const openStackFrameInEditorMiddleware = require(ReactNativeServerMiddlewarePath + '/openStackFrameInEditorMiddleware');
const copyToClipBoardMiddleware = require(ReactNativeServerMiddlewarePath +'/copyToClipBoardMiddleware');
const statusPageMiddleware = require(ReactNativeServerMiddlewarePath + '/statusPageMiddleware');
const systraceProfileMiddleware = require(ReactNativeServerMiddlewarePath + '/systraceProfileMiddleware');
const cpuProfilerMiddleware = require(ReactNativeServerMiddlewarePath + '/cpuProfilerMiddleware');
const indexPageMiddleware = require(ReactNativeServerMiddlewarePath + '/indexPage');
const unless = require(ReactNativeServerMiddlewarePath +'/unless');
//util
const ReactNativeServerUtilPath = 'react-native/local-cli/server/util';
const InspectorProxy = require(ReactNativeServerUtilPath + '/inspectorProxy.js');
const webSocketProxy = require(ReactNativeServerUtilPath + '/webSocketProxy.js');
const messageSocket = require(ReactNativeServerUtilPath + '/messageSocket.js');
const inspectorProxy = new InspectorProxy();
var wsProxy = null;
var ms = null;
const app = express();
const compiler = webpack(config);
app.use(function(req, res, next) {
// console.log(`Using middleware for ${req.url}`);
next();
});
app.use(liveReloadmiddleware(compiler));
app.use(require('webpack-dev-middleware')(compiler, {
publicPath: config.output.publicPath
}));
let args = {
port: 8081,
projectRoots: [path.resolve(__dirname, '../../')]
};
app.use(hotloadmiddleware(compiler));
app.use(loadRawBodyMiddleware);
app.use(getDevToolsMiddleware(args, () => wsProxy && wsProxy.isChromeConnected()))
app.use(getDevToolsMiddleware(args, () => ms && ms.isChromeConnected()))
app.use(openStackFrameInEditorMiddleware(args))
app.use(copyToClipBoardMiddleware)
app.use(statusPageMiddleware)
app.use(systraceProfileMiddleware)
app.use(cpuProfilerMiddleware)
app.use(indexPageMiddleware)
app.use(unless('/inspector', inspectorProxy.processRequest.bind(inspectorProxy)))
let serverInstance = app.listen(8081,'127.0.0.1',function(err) {
if (err) {
return console.error(err);
}
wsProxy = webSocketProxy.attachToServer(serverInstance, '/debugger-proxy');
ms = messageSocket.attachToServer(serverInstance, '/message');
inspectorProxy.attachToServer(serverInstance, '/inspector');
console.log('Listening at http://localhost:8081/');
});
});