How to use express-react-views - 10 common examples

To help you get started, we’ve selected a few express-react-views examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reactjs / express-react-views / examples / simple / app.js View on Github external
var http = require('http');
var path = require('path');
var errorHandler = require('errorhandler');
var logger = require('morgan');

// This should refer to the local React and gets installed via `npm install` in
// the example.
var reactViews = require('express-react-views');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jsx');
app.engine('jsx', reactViews.createEngine());
app.use(logger('dev'));
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(errorHandler());
}

app.locals.something = 'value';
app.locals.qaz = 'qut';

app.get('/', routes.index);
app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function() {
  console.log('Express server listening on port ' + app.get('port'));
github zwhu / blog / app.js View on Github external
var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jsx');

var options = {
    jsx: {
        harmony: true
    }
};
app.engine('jsx', require('express-react-views').createEngine(options));

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
github alexgibson / monosyn / app.js View on Github external
var compression = require('compression');
var errorHandler = require('errorhandler');
var favicon = require('serve-favicon');
var logger = require('morgan');
var methodOverride = require('method-override');
var multer = require('multer');
var path = require('path');
var reactViews = require('express-react-views');
var routes = require('./routes');
var utils = require('./lib/utils');

// all environments
app.set('port', process.env.PORT || 8000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jsx');
app.engine('jsx', reactViews.createEngine());
app.use(compression());
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(methodOverride());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(multer());
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
    app.use(errorHandler());
}

app.get('/', routes.index);
app.get('/r/', routes.remote);
github jeresig / pharos-images / server / express.js View on Github external
module.exports = (app) => {
    /* istanbul ignore if */
    if (config.NODE_ENV !== "test") {
        // A basic logger for tracking who is accessing the service
        app.use(morgan("dev"));
    }

    // Configure all the paths for serving the static content on the site
    app.use(serveFavicon(`${rootPath}/public/images/favicon.png`));
    app.use(serveStatic(`${rootPath}/public`));
    app.use("/data", serveStatic(`${rootPath}/data`));

    // Configure how the views are handled (with React)
    app.engine("jsx", reactViews.createEngine({
        transformViews: false,
    }));
    app.set("views", `${rootPath}/views`);
    app.set("view engine", "jsx");

    // Enable caching of the view files by Express, but only in production
    app.set("view cache", config.NODE_ENV === "production");

    // Parses the contents of HTTP POST bodies, handling URL-encoded forms
    // and also JSON blobs
    app.use(bodyParser.urlencoded({
        extended: true,
    }));

    // Adds in support for overriding HTTP verbs to help
    // clients support DELETE and PUT
github getguesstimate / guesstimate-app / server.js View on Github external
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');

var express    = require('express');        // call express
var bodyParser = require('body-parser');
var app        = express();                 // define our app using express
var mongoose = require('mongoose');
var router = express.Router();              // get an instance of the express Router
var path = require('path');
mongoose.connect('mongodb://oagr:password@proximus.modulusmongo.net:27017/tas3uZuj');
var jsx = require('express-react-views').createEngine({jsx: {harmony: true}});
var traceur = require('traceur');
traceur.require.makeDefault(function(file) {
  return file.indexOf('node_modules') == -1;
});

app.use(express.static(path.join(__dirname, 'public')));
app.set('views', __dirname + '/scripts/views');
app.set('view engine', 'jsx');
app.engine('jsx', jsx)

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

var comments = [{author: 'Pete Hunt', text: 'Hey there!'}];

app.all('/', function(req, res, next) {
github frictionlessdata / data-quality-dashboard / app / bootstrap.js View on Github external
export default function bootstrap(app, express) {
  let viewPath = path.join(__dirname, 'backend', 'views')
  let publicPath = path.join(path.dirname(__dirname), 'public')
  // NOTE: We compile ES6 at runtime, in server.js, hence transformViews is
  // false due to some weirdness in express-react-views
  // https://github.com/reactjs/express-react-views/issues/40
  let viewEngine = createEngine({transformViews: false})
  let backendCache = new NodeCache()

  app.set('config', config)
  app.set('port', config.get('port'))
  app.set('cache', backendCache)
  app.set('views', viewPath)
  app.set('view engine', 'jsx')
  app.engine('jsx', viewEngine)
  app.use(express.static(publicPath))
  app.use([
    middlewares.getInstance,
    middlewares.getDB,
    middlewares.setLocals
  ])
  app.use('', routes())
  return app
github Lucifier129 / react-imvc / src / entry / server.ts View on Github external
}

	// handle favicon
	if (config.favicon) {
		app.use(favicon(config.favicon))
	}

	// handle view engine
	const viewsConfig = {
		...config.ReactViews,
		babel: {
			...configBabel,
			extensions: [".es6", ".es", ".jsx", ".js", ".mjs", ".ts", ".tsx"]
		}
	}
	app.engine("js", require("express-react-views").createEngine(viewsConfig))
	app.engine("jsx", require("express-react-views").createEngine(viewsConfig))
	app.engine("ts", require("express-react-views").createEngine(viewsConfig))
	app.engine("tsx", require("express-react-views").createEngine(viewsConfig))

	// view engine setup
	app.set("views", path.join(config.root, config.routes))
	app.set("view engine", "js") // default view engine ext .js

	// handle logger
	if (config.logger) {
		app.use(logger(config.logger))
	}

	// handle bodyParser
	if (config.bodyParser) {
		if (config.bodyParser.json) {
github reactjs / express-react-views / examples / dynamic / app.js View on Github external
var express = require('express');
var reactViews = require('express-react-views');

var app = express();

app.set('view engine', 'js');
app.engine('js', reactViews.createEngine());

app.use(express.static(__dirname + '/public'));

app.get('/', function(req, res) {
  var initialState = {
    items: [
      'document your code',
      'drop the kids off at the pool',
      '',
    ],
    text: '',
  };
  res.render('Html', {data: initialState});
});

var port = process.env.PORT || 3000;
github heimashi / easy_mock_api / app.js View on Github external
var express = require('express');
var reactViews = require('express-react-views');
var bodyParser = require('body-parser');
var fs = require('fs');

var app = express();
app.set('views', __dirname + '/views');
app.set('view engine', 'jsx');
app.engine('jsx', reactViews.createEngine());

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.get('/', function (req, res, next) {
  res.render('index', { title:'admin',msg: "@sw"});
});

app.get('/api', function (req, res, next) {
  res.render('api_post', { title:'API POST',msg1: "url example: /aa/bb/cc",msg2:"json example: {\"key1\":\"value\",\"key2\":1}"});
});



var url_json_list = {};
var url_list = new Array();
github workshopper / learnyoureact / exercises / css / solution / solution.js View on Github external
var express = require('express');
var app = express();

app.set('port', (process.argv[2] || 3000));
app.set('view engine', 'jsx');
app.set('views', __dirname + '/views'); 
app.engine('jsx', require('express-react-views').createEngine());

app.use('/', function(req, res) {
	res.render('index', '');
});

app.listen(app.get('port'), function() {});

express-react-views

This is an Express view engine which renders React components on server. It renders static markup and *does not* support mounting those views on the client.

BSD-3-Clause
Latest version published 6 years ago

Package Health Score

56 / 100
Full package analysis

Popular express-react-views functions