Open 009topersky opened 6 years ago
which version of node.js are you running?
node version v6.11.4
Not sure where the error is coming from as it is working ok on ubuntu with node.js versions 5 and above.
However, just completed a version using docker containers which you can find on the develop branch - https://github.com/IHTSDO/sct-snapshot-rest-api/tree/develop. This might bypass any issues that running node.js on Windows may be introducing.
Good day sir!
Currently i'm working on Windows 10 Environment
still i have the issue and i'm stuck :(
Moving forward.,
how can i get the 1.3 version of rf2-to-json-conversion
https://github.com/IHTSDO/rf2-to-json-conversion NOTE ensure you are using versions 1.3 and above of the conversion tool to create the JSON files. Older versions will not work.
You can find it here - https://github.com/IHTSDO/rf2-to-json-conversion/releases/tag/1.3
Hi, I had this problem earlier as the status code was returning as text instead of code. You need to make changes to your app.js at 2 places i guess
In place of (pls comment the below portion) /res.send('error', { message: err.message, error: {} });/ And change it to the below statement res.status(err.status >= 100 && err.status < 600 ? err.code : 500).send(err.message);
This should work
@rorydavidson , using the development branch, now I have the message from the server (RESTful API) "There are no data for this conceptId:
I Got this error !
RangeError: Invalid status code: 0 at ServerResponse.writeHead (_http_server.js:192:11) at ServerResponse.writeHead (C:\Users\lenovo\Documents\SNOMED\mean\server\sct-snapshot-rest-api\node_modules\on-headers\index.js:55:19) at ServerResponse._implicitHeader (_http_server.js:157:8) at ServerResponse.OutgoingMessage.end (_http_outgoing.js:573:10) at ServerResponse.send (C:\Users\lenovo\Documents\SNOMED\mean\server\sct-snapshot-rest-api\node_modules\express\lib\response.js:211:10) at ServerResponse.json (C:\Users\lenovo\Documents\SNOMED\mean\server\sct-snapshot-rest-api\node_modules\express\lib\response.js:256:15) at ServerResponse.send (C:\Users\lenovo\Documents\SNOMED\mean\server\sct-snapshot-rest-api\node_modules\express\lib\response.js:158:21) at C:\Users\lenovo\Documents\SNOMED\mean\server\sct-snapshot-rest-api\app.js:104:33 at Layer.handle_error (C:\Users\lenovo\Documents\SNOMED\mean\server\sct-snapshot-rest-api\node_modules\express\lib\router\layer.js:71:5) at trim_prefix (C:\Users\lenovo\Documents\SNOMED\mean\server\sct-snapshot-rest-api\node_modules\express\lib\router\index.js:315:13)
This is my app.js
var express = require('express'); var path = require('path'); // var favicon = require('static-favicon'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var MongoClient = require('mongodb').MongoClient; var fs = require('fs'); var pidFile = process.env.PID_FILE || '/var/sct-snapshot-rest-api.pid';
fs.writeFile(pidFile, process.pid);
var routes = require('./routes/index'); var snomed = require('./routes/snomed'); var util = require('./routes/util'); var server = require('./routes/server'); var expressions = require('./routes/expressions');
var accessControlConfig = { allowOrigin: '*', allowMethods: 'GET,POST,PUT,DELETE,HEAD,OPTIONS' };
// ****
var app = express(); // view engine setu // p app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'pug');
// app.use(favicon()); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req, res, next) { var oneof = false; if (req.headers.origin) { res.header('Access-Control-Allow-Origin', req.headers.origin); oneof = true; } if (req.headers['access-control-request-method']) { res.header( 'Access-Control-Allow-Methods', req.headers['access-control-request-method'] ); oneof = true; } if (req.headers['access-control-request-headers']) { res.header( 'Access-Control-Allow-Headers', req.headers['access-control-request-headers'] ); oneof = true; }
if (oneof) { res.header('Access-Control-Max-Age', 60 60 24 * 365); }
res.header('Access-Control-Allow-Credentials', true);
// intercept OPTIONS method if (oneof && req.method == 'OPTIONS') { res.send(200); } else { next(); } });
app.use('/', routes); app.use('/snomed', snomed); app.use('/util', util); app.use('/server', server); app.use('/expressions', expressions);
/// 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('error', { message: err.message, error: err }); }); }
// production error handler // no stacktraces leaked to user // Adding raw body support app.use(function(err, req, res, next) { res.status(err.status || 500); res.send('error', { message: err.message, error: err });
// var data=''; // req.setEncoding('utf8'); // req.on('data', function(chunk) { // data += chunk; // }); // // req.on('end', function() { // req.body = data; // next(); // }); });
var cluster = require('cluster'); var port = process.env.PORT || 3000; // var port = 3001;
if (cluster.isMaster) { var numWorkers = require('os').cpus().length;
console.log('Master cluster setting up ' + numWorkers + ' workers...');
for (var i = 0; i < numWorkers; i++) { cluster.fork(); }
cluster.on('online', function(worker) { console.log('Worker ' + worker.process.pid + ' is online'); });
cluster.on('exit', function(worker, code, signal) { console.log( 'Worker ' + worker.process.pid + ' died with code: ' + code + ', and signal: ' + signal ); console.log('Starting a new worker'); cluster.fork(); }); } else { //var app = require('express')(); // app.all('/*', function(req, res) {res.send('process ' + process.pid + ' says hello!').end();})
var server = app.listen(port, function() { console.log( 'Process ' + process.pid + ' is listening in port ' + port + ' to all incoming requests' ); }); }
// var server = require('http').Server(app); // // server.listen(port); // // console.log('Express app started on port '+port);
module.exports = app; module.exports.accessControlConfig = accessControlConfig;
and this is my server.js
var express = require('express'); var router = express.Router(); var fs = require('fs'); var MongoClient = require('mongodb').MongoClient; var ObjectID = require('mongodb').ObjectID;
var serverDb; var resourcesCol;
MongoClient.connect('mongodb://localhost:27017/server', function(err, db) { if (err) { console.warn(getTime() + ' - ' + err.message); res.status(500).send(err.message); return; }
serverDb = db; // serverDb = db.db(sampleManifest.databaseName);
// resourcesCol = db.collection('resources'); resourcesCol = db.collection(sampleManifest.collectionName);
console.log('hahah 123'); console.log(serverDb); console.log('hahah 22222'); console.log(db); console.log('hahah 33333'); console.log(resourcesCol); console.log('Connected to server/resources db.'); });
router.get('/releases', function(req, res) { resourcesCol.find().toArray(function(err, doc) { if (err) { console.log(err.message); } if (doc) { res.status(200); res.header('Content-Type', 'application/json'); res.send(doc); } else { res.status(200); res.send('Manifest not found for id = ' + idParam); } }); });
router.get('/releases/:id', function(req, res) { var idParam = ObjectID.createFromHexString(req.params.id); if (idParam) { resourcesCol.find({ _id: idParam }).nextObject(function(err, doc) { if (err) { console.log(err.message); } if (doc) { res.status(200); res.header('Content-Type', 'application/json'); res.send(doc); } else { res.status(200); res.send('Manifest not found for id = ' + idParam); } }); } else { res.status(200); res.send('Not a valid id'); } });
module.exports = router;
var getTime = function() { var currentdate = new Date(); var datetime = 'Last Sync: ' + currentdate.getDate() + '/' + (currentdate.getMonth() + 1) + '/' + currentdate.getFullYear() + ' @ ' + currentdate.getHours() + ':' + currentdate.getMinutes() + ':' + currentdate.getSeconds(); return datetime; }; // Manifest model var sampleManifest = { id: '4b7865c0-18e0-11e4-8c21-0800200c9a66', resourceSetName: 'International Edition', effectiveTime: '20180131', databaseName: 'en-edition', collectionName: '20180131', expirationDate: '20180731', modules: [ { conceptId: '900000000000012004', defaultTerm: 'SNOMED CT model component module (core metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { conceptId: '900000000000207008', defaultTerm: 'SNOMED CT core module (core metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' } ], languageRefsets: [ { conceptId: '900000000000509007', defaultTerm: 'United States of America English language reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { conceptId: '900000000000508004', defaultTerm: 'Great Britain English language reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' } ], refsets: [ { count: 44950, type: 'ASSOCIATION', conceptId: '900000000000527005', defaultTerm: 'SAME AS association reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { count: 17069, type: 'ASSOCIATION', conceptId: '900000000000524003', defaultTerm: 'MOVED TO association reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { count: 285880, type: 'ATTRIBUTE_VALUE', conceptId: '900000000000490003', defaultTerm: 'Description inactivation indicator attribute value reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { count: 319, type: 'ASSOCIATION', conceptId: '734139008', defaultTerm: 'Anatomy structure and part association reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20170731', module: '900000000000012004' }, { count: 177, type: 'ASSOCIATION', conceptId: '900000000000530003', defaultTerm: 'ALTERNATIVE association reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { count: 818, type: 'ASSOCIATION', conceptId: '900000000000531004', defaultTerm: 'REFERS TO concept association reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { count: 14093, type: 'ASSOCIATION', conceptId: '734138000', defaultTerm: 'Anatomy structure and entire association reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20170731', module: '900000000000012004' }, { count: 19687, type: 'SIMPLE_REFSET', conceptId: '723264001', defaultTerm: 'Lateralizable body structure reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20170131', module: '900000000000012004' }, { count: 32413, type: 'ASSOCIATION', conceptId: '900000000000523009', defaultTerm: 'POSSIBLY EQUIVALENT TO association reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { count: 99169, type: 'ATTRIBUTE_VALUE', conceptId: '900000000000489007', defaultTerm: 'Concept inactivation indicator attribute value reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { count: 24308, type: 'SIMPLEMAP', conceptId: '446608001', defaultTerm: 'ICD-O simple map reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { count: 448215, type: 'SIMPLEMAP', conceptId: '900000000000497000', defaultTerm: 'CTV3 simple map reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { count: 5872, type: 'ASSOCIATION', conceptId: '900000000000526001', defaultTerm: 'REPLACED BY association reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' }, { count: 21609, type: 'ASSOCIATION', conceptId: '900000000000528000', defaultTerm: 'WAS A association reference set (foundation metadata concept)', definitionStatus: 'Primitive', statedDescendants: 0, inferredDescendants: 0, active: true, effectiveTime: '20020131', module: '900000000000012004' } ], languageRefsetsAbbrev: {}, defaultTermLangCode: 'en', defaultTermType: '900000000000003001', defaultTermLangRefset: '900000000000509007', textIndexNormalized: true };