Skip to content

Commit b8aabbc

Browse files
committed
Optimization ssr-caching and Production CORS setting
1 parent d23de23 commit b8aabbc

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"body-parser": "latest",
1818
"compression": "^1.7.2",
1919
"connect-mongo": "^2.0.1",
20+
"cors": "^2.8.4",
2021
"crypto": "^1.0.1",
2122
"express": "^4.16.3",
2223
"express-flash": "0.0.2",

server/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const LRUCache = require('lru-cache');
1313
const logger = require('morgan');
1414
const flash = require('express-flash');
1515
const MongoStore = require('connect-mongo')(session);
16-
16+
const cors = require('cors');
1717

1818
/**
1919
* Controllers
@@ -75,6 +75,7 @@ app.prepare()
7575
}));
7676
server.use(passport.initialize());
7777
server.use(flash());
78+
server.use(cors());
7879

7980
/**
8081
* Connect to MongoDB.
@@ -94,7 +95,9 @@ app.prepare()
9495
/**
9596
* Primary app routes.
9697
*/
97-
// server.get('/', homeController.index(app));
98+
server.get('/', (req, res) => {
99+
renderAndCache(req, res, '/');
100+
});
98101

99102
server.get('/account/login', userController.getLogin(app));
100103
server.post('/account/login', userController.postLogin(app));
@@ -105,9 +108,14 @@ app.prepare()
105108
res.send('hello world');
106109
});
107110

111+
server.get('/ucsc', (req, res) => {
112+
renderAndCache(req, res, '/ucsc');
113+
});
114+
108115
server.get('/ucsd', (req, res) => {
109116
const itemData = api.getGraphData();
110-
app.render(req, res, '/ucsd', {itemData: itemData});
117+
renderAndCache(req, res, '/ucsd', {itemData: itemData});
118+
// app.render(req, res, '/ucsd', {itemData: itemData});
111119
});
112120

113121
/**

0 commit comments

Comments
 (0)