Add index page for packager

Summary:
When packager is running, visiting localhost:8081 produces ugly 404 "GET / not found"
This diff adds a simple index.html page that has a title and link to documentation.

It's a super tiny detail, but I hope it makes things a little nicer. Improvements are welcome.

Maybe we could include an offline copy of React Native's docs website?

Reviewed By: vjeux

Differential Revision: D3341242

fbshipit-source-id: c8cd4b647e69eb520ea8bc978bea070551225912
This commit is contained in:
Alex Kotliarskyi 2016-05-24 11:54:28 -07:00 committed by Facebook Github Bot 6
parent 0e8c3ff463
commit 11449359e5
3 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>React Native</title>
</head>
<body>
<p>React Native packager is running.</p>
<p><a href="http://facebook.github.io/react-native/">Visit documentation</a></p>
</body>
</html>

View File

@ -0,0 +1,20 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
const fs = require('fs');
const path = require('path');
module.exports = function(req, res, next) {
if (req.url === '/') {
res.end(fs.readFileSync(path.join(__dirname, 'index.html')));
} else {
next();
}
};

View File

@ -20,6 +20,7 @@ const openStackFrameInEditorMiddleware = require('./middleware/openStackFrameInE
const path = require('path');
const ReactPackager = require('../../packager/react-packager');
const statusPageMiddleware = require('./middleware/statusPageMiddleware.js');
const indexPageMiddleware = require('./middleware/indexPage');
const systraceProfileMiddleware = require('./middleware/systraceProfileMiddleware.js');
const webSocketProxy = require('./util/webSocketProxy.js');
@ -36,6 +37,7 @@ function runServer(args, config, readyCallback) {
.use(statusPageMiddleware)
.use(systraceProfileMiddleware)
.use(cpuProfilerMiddleware)
.use(indexPageMiddleware)
.use(packagerServer.processRequest.bind(packagerServer));
args.projectRoots.forEach(root => app.use(connect.static(root)));