-
Notifications
You must be signed in to change notification settings - Fork 15
Description
I am trying to rewrite this with React-router new version.But I can't fix this error.
import express from 'express';
import mysql from 'mysql';
import webpack from 'webpack';
import path from 'path';
import config from './webpack.config.dev';
import React from 'react';import Router from 'react-router';
import Helmet from 'react-helmet';
import routes from './src/App';const app = express();
const compiler = webpack(config);
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
//
// app.use(require('webpack-hot-middleware')(compiler));app.set('view engine','ejs');
app.use(express.static('./public'));
const pool = mysql.createPool({
connectionLimit:100,
host:'127.0.0.1',
user:'root',
password:'123456',
database:'naveen'
});app.get('*',function (req,res) {
let router = Router.create({
location:req.url,
routes:routes
});
router.run(function (Root,state) {
let renderedBody = React.renderToString();
let head = Helmet.rewind();let html = ` <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>${head.title}</title> ${head.meta} ${head.link} </head> <body> <div id="app">${renderedBody}</div> <script src="./public/bundle.js"></script> </body> </html> `; res.write(html); res.end(); })});
app.get('/api',function (req,res) {
pool.getConnection(function (err,connection) {
connection.query('SELECT * FROM users',function (err,rows) {
if(err) throw err;
console.log(rows[0]);
res.send(rows);
connection.release()
})
})
});
const port = 3000;
console.log(Server Initializing ${port});
app.listen(port,function (err) {
if(err) throw err;
console.log(I am Alive at ${port})
});