Awesome
FieldDBWebServer
================
Web Server for FieldDB corpus pages, and the project website.
Installation
Install Node.js
You need Node.js to run this webserver.
Mac:
$ brew install node
Linux:
$ sudo apt-get install nodejs
Windows:
You can download node from http://nodejs.org
Install dependancies
$ npm install
Configure
You can create a config/local.js
file to point to the corpus service you want to contact. By default it contacts your localhost.
Run
To turn on the server:
$ npm run watch
To develop offline with fixture data:
$ OFFLINE=true npm start --offline
Then open https://localhost:3182 and accept the security certificate warning since you are developing locally with a self signed certificate.
To debug the client side code as well, in another tab turn on the webpack server:
$ node webpack.server.js
Then open https://localhost:3001/ and accept the security certificate warning since you are developing locally with a self signed certificate.
How to set up a production server
Running in production isn't much different from running while developing, except you will probably want to do some more customization of the configuration.
However, if you specified a port in the config, you might need someone with sudo
privilges to open the port to the outside world so it will be accessible to the other machines who want to contact this service. Some universities and companies block non-standard ports so if you might have users who might be affected, you could request that someone with sudo
priveleges set up a proxy such as Nginx or Apache to serve using a virtual host (eg https://www.example.org) rather than through a port (eg https://example.org:3182);
Configuration
You should copy the config/local.js
to config/production.js
$ cp config/local.js config/production.js
Suggested changes:
- change the
port
to the port you want to use - change
ssl
to have the path of your ssl certificates and key, - change
corpus
to the corpus service you want to contact, and
Production mode is controlled by an environment variable. Here is how you would set the environment variables if you are running the server via a non-privileged user fielddb
.
$ echo FIELDDB_HOME=/home/fielddb/fielddbhome >> ~/.bashrc
$ echo NODE_ENV=production >> ~/.bashrc
Finally turn on the service in a way that it will restart even in the case of errors:
$ gulp build
$ ./start_service
Development
This project uses server-side rendering with the React library so that component code can be shared between server and browser, as well as getting fast initial page loads and search-engine-friendly pages.
Try viewing the page source to ensure the HTML being sent from the server is already rendered (with checksums to determine whether client-side rendering is necessary).
Redux server side render is based on from mz026.
- Universal rendering, with async data support
- Server side redirect
- Separate vendor and app js files
- Use Immutable as store data
Stack:
- react@15.4.2
- react-router@2.8.1
- Immutable.js
- Webpack@2.2
- Babel@6
- Express as isomorphic server
npm
as package manager
Testing:
- Mocha as testing framework
- Chai as assertion library
- Rewire and Sinon to mock/stub
- Enzyme to do React rendering
In development mode:
Assign static folder linking /assets
to the folder above
In production mode:
Use a gulp task (gulp build
) to handle it:
- A set of
[rev](https://github.com/smysnk/gulp-rev-all)-ed
assets with hash code appended would be built intodist/public/assets
- A static middleware mapping root url to the folder mentioned above is configured in
server.js
- A set of
[revReplace](https://github.com/jamesknelson/gulp-rev-replace)-ed
server code would be built intodist/server-build
, so that the rev-ed assets can be used when doing server rendering
To test your production build:
$ gulp build
$ NODE_ENV=production npm start
Deployment:
To deploy this app to production environment:
-
Run
$ NODE_ENV=development npm install
on server- After the installation above, then run
$ npm run build:production
which will build the front-end related assets and rev-ed server code underdist/
folder.
- After the installation above, then run
-
Kick off the server with:
$ npm run start:production
- Once you're sure the server is operational, start the service with forever:
$./start_service
Release History
- v1.62 activity heat map
- v1.72 display of terms of use and elastic search integration
- v3.19 refactored server.js into routes and updated express 2.x to 4.x
- v3.21.15 migrated public urls from jade to handlebars
- v5.4.21 migrated public urls from handlebars to react
- v5.168.15 upgraded to node 12
License
Licensed under the Apache, 2.0 licenses.