forked from spikebrehm/isomorphic-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (23 loc) · 866 Bytes
/
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
var express = require('express')
, app = express()
, port = process.env.PORT || 3030
, apiPort = process.env.API_PORT || 3031
, api = require('./lib/api')
, routes = require('./app/routes')
, Router = require('./app/router')
, router = new Router(routes)
;
app.use(express.static(__dirname + '/public'));
// Mount the routes defined in `./app/routes` on our server.
app.use(router.middleware());
// On the client, we want to be able to just send API requests to the
// main web server using a relative URL, so we proxy requests to the
// API server here.
app.use('/api', api.proxyMiddleware(apiPort));
app.listen(port);
// Run the API server on a separate port, so we can make
// HTTP requests to it from within our main app.
api.listen(apiPort);
console.log('Tutorial running on port %s; API on port %s',
port,
apiPort);