server.js 754 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. module.exports = {
  3. init: init
  4. };
  5. var express = require('express'),
  6. bodyParser = require('body-parser'),
  7. cors = require('cors'),
  8. routes = require('./routes.js');
  9. function init(hueConfig) {
  10. var app = express();
  11. app.use(express.static('frontend'));
  12. app.use(bodyParser.json());
  13. app.use(cors());
  14. app.get ('/api/config', routes.getConfig);
  15. app.get ('/api/fullState', routes.getFullState);
  16. app.get ('/api/lights', routes.getLights);
  17. app.post('/api/lights/:id', routes.setLight);
  18. routes.init(hueConfig, function (error) {
  19. if (error) return console.error(error);
  20. app.listen(3000, function () {
  21. console.log('Server listening on port 3000');
  22. });
  23. });
  24. }