-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (19 loc) · 803 Bytes
/
server.js
File metadata and controls
31 lines (19 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import fs from 'fs';
import path from 'path';
import express from 'express';
import React from 'react';
import { renderToString } from 'react-dom/server';
import ContactApp from './app/components/ContactApp';
const app = express();
app.set('views', './views');
app.set('view engine', 'ejs');
app.use(express.static(path.resolve(__dirname, '/static')));
const contacts = JSON.parse(fs.readFileSync(__dirname + '/public/contacts.json', 'utf8'));
const ContactAppFactory = React.createFactory(ContactApp);
app.get('/', (req, res) => {
let componentInstance = ContactAppFactory({contacts:contacts});
res.render('index', {reactInitialData: JSON.stringify(contacts), content: renderToString(componentInstance)});
});
app.listen(3000, ()=> {
console.log('Express app listening on port 3000');
})