Commit b0f807f8 authored by andreagerino's avatar andreagerino

Initial import of Icarus Server

parents
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="IcarusServer node_modules" level="project" />
</component>
</module>
\ No newline at end of file
var express = require('express');
var path = require('path');
var logger = require('morgan');
var bodyParser = require('body-parser');
var storage = require('./routes/storage');
var services = require('./routes/services');
var app = express();
app.use(logger('dev'));
app.use(bodyParser.json());
app.use('/str', storage);
app.use('/svc', services);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.send({
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.send({
message: err.message,
error: {}
});
});
module.exports = app;
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('Icarus:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
{
"name": "Icarus",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.13.2",
"debug": "~2.2.0",
"express": "~4.13.1",
"mongodb": "~2.0",
"morgan": "~1.6.1",
"sleep": "~3.0.0"
}
}
var express = require('express');
var router = express.Router();
var ip_service = require('./services/invisiblepuzzle/invisiblepuzzle');
var echo_service = require('./services/echo/echo');
router.use('/ip', ip_service);
router.use('/echo', echo_service);
router.get('/', function(req, res, next) {
res.send({
"services": ["echo","ip"]
});
});
module.exports = router;
\ No newline at end of file
var express = require('express');
var router = express.Router();
/* GET root. */
router.all('/', function(req, res, next) {
res.send(req.body);
});
module.exports = router;
var express = require('express');
var router = express.Router();
/* GET root . */
router.get('/', function(req, res, next) {
res.sendStatus(200);
});
module.exports = router;
var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
res.sendStatus(200);
});
module.exports = router;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment