Skip to content

Instantly share code, notes, and snippets.

@nsfmc
Created July 12, 2018 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsfmc/44ba92b5277e8e47fb75b09d0ec1b7a3 to your computer and use it in GitHub Desktop.
Save nsfmc/44ba92b5277e8e47fb75b09d0ec1b7a3 to your computer and use it in GitHub Desktop.
super minimal server react setup
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import express from 'express'
const app = express();
app.get('/', (_, res) => {
console.log()
const App = () => <p>ohayo</p>;
const reactContent = ReactDOMServer.renderToString(<App />);
res.send(reactContent);
});
const {PORT = 8181} = process.env;
console.log(`about to listen on 0.0.0.0:${PORT}`);
app.listen(PORT);
{
"name": "simple-server",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"watch": "NODE_ENV=development webpack -w",
"build": "NODE_ENV=production webpack",
"serve": "nodemon dist/dist.js"
},
"dependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"express": "^4.16.3",
"nodemon": "^1.18.1",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"webpack": "^4.16.0",
"webpack-cli": "^3.0.8"
}
}
module.exports = {
entry: './index.js',
output: {
filename: 'dist.js',
},
devtool: 'source-map',
mode: process.env.NODE_ENV || 'production',
target: 'node',
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [['env', {'targets': {node: 'current'}}], 'react'],
}
}
},
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment