Initial commit
This commit is contained in:
16
src/server/dataProvider/index.js
Normal file
16
src/server/dataProvider/index.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const mapping = {
|
||||
product_detail: (store) => {
|
||||
console.log("mapper");
|
||||
return Promise.resolve(store);
|
||||
},
|
||||
authentication: (store) => {
|
||||
return Promise.resolve(store);
|
||||
}
|
||||
};
|
||||
|
||||
export function provideData(store, routes) {
|
||||
if (routes && routes[1] && routes[1].name && mapping[routes[1].name]) {
|
||||
return mapping[routes[1].name](store);
|
||||
}
|
||||
return Promise.resolve(store);
|
||||
}
|
||||
62
src/server/server.js
Normal file
62
src/server/server.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import {Provider} from 'mobx-react';
|
||||
import http from 'http';
|
||||
import https from 'https';
|
||||
import debug from 'debug';
|
||||
import express from 'express';
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const webpack = require('webpack');
|
||||
const webpackConfig = require('./../../webpack.config');
|
||||
const compression = require('compression');
|
||||
const cors = require('cors');
|
||||
const rt = require("thumb-express");
|
||||
const compiler = webpack(webpackConfig);
|
||||
const app = express();
|
||||
const HTML = fs.readFileSync(path.join(__dirname, '..', '..', 'public', 'index.html'), 'utf-8');
|
||||
|
||||
const renderView = (renderProps, appstate) => {
|
||||
const initialState = {
|
||||
appstate: appstate.toJson()
|
||||
};
|
||||
return HTML//.replace('<!--rootComponent-->', componentHTML);
|
||||
};
|
||||
|
||||
const shouldCompress = (req, res) => {
|
||||
if (req.headers['x-no-compression']) {
|
||||
// don't compress responses with this request header
|
||||
return false
|
||||
}
|
||||
|
||||
// fallback to standard filter function
|
||||
return compression.filter(req, res)
|
||||
}
|
||||
|
||||
|
||||
app.use(compression({filter: shouldCompress}));
|
||||
app.use(cors());
|
||||
app.use(rt.init(__dirname + '/../../assets'));
|
||||
app.use(express.static(__dirname + '/../../assets'));
|
||||
app.use('/assets', express.static(__dirname + '/../../assets'));
|
||||
app.use(require("webpack-dev-middleware")(compiler, {
|
||||
publicPath: webpackConfig.output.publicPath,
|
||||
noInfo: true
|
||||
}));
|
||||
app.use(require("webpack-hot-middleware")(compiler, {
|
||||
log: console.log,
|
||||
path: '/__webpack_hmr',
|
||||
heartbeat: 10 * 1000,
|
||||
reload: true
|
||||
}));
|
||||
app.use((req, res) => {
|
||||
res.send(HTML);
|
||||
});
|
||||
|
||||
const port = process.env.PORT || 7700;
|
||||
app.set('port', port);
|
||||
const server = app.listen(app.get('port'), (err, result) => {
|
||||
console.log('--------------------------');
|
||||
console.log('Server started');
|
||||
console.log('Listening at http://localhost:' + app.get('port') + '/');
|
||||
console.log('--------------------------')
|
||||
});
|
||||
Reference in New Issue
Block a user