Add cookie-parser and body-parser middlewares

master
Ian Mancini 4 years ago
parent 65c81cbddb
commit 9caa9c1a87

@ -9,11 +9,14 @@
"dependencies": { "dependencies": {
"@react-ssr/core": "^0.21.18", "@react-ssr/core": "^0.21.18",
"@react-ssr/express": "^0.21.18", "@react-ssr/express": "^0.21.18",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"express": "^4.17.1", "express": "^4.17.1",
"react": "^16.13.0", "react": "^16.13.0",
"react-dom": "^16.13.0" "react-dom": "^16.13.0"
}, },
"devDependencies": { "devDependencies": {
"@types/cookie-parser": "^1.4.2",
"@types/express": "^4.17.1", "@types/express": "^4.17.1",
"@types/node": "^12.11.6", "@types/node": "^12.11.6",
"@types/react": "^16.9.11", "@types/react": "^16.9.11",

@ -1,7 +1,20 @@
import http from 'http';
import express, { Request, Response } from 'express'; import express, { Request, Response } from 'express';
import bodyParser from 'body-parser'
import cookieParser from 'cookie-parser'
// import passport from 'passport';
import register from '@react-ssr/express/register'; import register from '@react-ssr/express/register';
const app = express(); const app = express();
app.set('trust proxy', 1);
const server = http.createServer(app);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
// initPassport();
// app.use(passport.initialize());
(async () => { (async () => {
await register(app); await register(app);
@ -11,7 +24,7 @@ const app = express();
res.render('index', { user }); res.render('index', { user });
}); });
app.listen(3000, () => { server.listen(3000, () => {
console.log('> Ready on http://localhost:3000'); console.log('> Ready on http://localhost:3000');
}); });
})(); })();

Loading…
Cancel
Save