Created
July 26, 2015 03:52
-
-
Save brysgo/17b0536381632eb67c27 to your computer and use it in GitHub Desktop.
React native staging environment setup... http://www.brysgo.com/development/tools/2015/07/26/react-native-on-heroku.html
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
#import "AppDelegate.h" | |
#import "RCTRootView.h" | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
NSDictionary *env = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"environment" ofType:@"plist"]]; | |
NSString *serverURLString = [NSString stringWithFormat:@"http://%@/index.ios.bundle", [env objectForKey:@"hostname"]]; | |
NSURL *codeURL = [NSURL URLWithString:serverURLString]; | |
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:codeURL | |
moduleName:@"ChatApp" | |
launchOptions:launchOptions]; | |
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | |
UIViewController *rootViewController = [[UIViewController alloc] init]; | |
rootViewController.view = rootView; | |
self.window.rootViewController = rootViewController; | |
[self.window makeKeyAndVisible]; | |
return YES; | |
} | |
@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
// server/proxy.js | |
var httpProxy = require('http-proxy'); | |
var proxy = httpProxy.createProxyServer(); | |
module.exports = function(http) { | |
return http.createServer(function(req, res) { | |
if (req.url.indexOf('index.ios') != -1) { | |
proxy.web(req, res, { target: 'http://localhost:8081' }); | |
} | |
}); | |
} |
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
// server/server.js | |
require('react-native/packager/packager.js'); | |
var http = require('./proxy')(require('http')); | |
var io = require('socket.io')(http); | |
var port = process.env.PORT || 3000; | |
io.on('connection', function(socket){ | |
socket.on('chat message', function(msg){ | |
io.emit('chat message', msg); | |
}); | |
}); | |
http.listen(port, function(){ | |
console.log('listening on *:' + port); | |
}); |
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
// js/utils/WebAPIUtils.js | |
window.navigator.userAgent = "react-native"; | |
var ServerActionCreators = require('../actions/ServerActionCreators'); | |
var io = require('../../node_modules/socket.io/node_modules/socket.io-client/socket.io'); | |
var React = require('react-native'); | |
var EnvironmentManager = require('react-native-env'); | |
var socket; | |
var serverUrl; | |
EnvironmentManager.get('hostname') | |
.then((val) => { | |
serverUrl = 'http://' + val; | |
socket = io(serverUrl, {jsonp: false}); | |
socket.on('connect', function(){ | |
socket.on('chat message', function(msg) { | |
ServerActionCreators.receiveMessage(msg); | |
}); | |
}); | |
}) | |
module.exports = { | |
sendMessage: function(msg) { | |
socket.emit('chat message', msg); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment