javascript - Node.js Error in routing -
first of sorry beginners question yet cannot seem out myself. working on app dispatch messages according 1 specific parameter in json. have following in app.config.json
<code> { "server": { "port": "8080" }, "auth":{ "users": { "xxx": "xxxxx" }, "unauthorizedresponse": "unauthorized!" }, "services": { "service one": { "address": "http://localhost", "port": "8000" } } } </code> and router is:
<code> const request = require('request'); const express = require("express"); const router = express.router(); const fs = require("fs"); const configs = json.parse(fs.readfilesync(__dirname + '/../app.config.json', 'utf8')); const services = configs.services; router.post('/', (req, res) => { let servicename = req.get('service-name'); if (services[servicename]) { let requestoptions = { uri: services[servicename].address + ":" + services[servicename].port, json: req.body } request.post(requestoptions, (error, response, body) => { res.send(body); }); } else { res.send("there no service named " + req.get("service-name")) } }); module.exports = router; </code> my problem trying add more services app.config.json ends giving me following error:
undefined:20 "service2": { ^ syntaxerror: unexpected string in json @ position 313 </code> any ideas?
thank in advance.
maybe missing , in json object. let's try this:
"service one": { "address": "http://localhost", "port": "8000" }, "service two": { "address": "http://localhost/route2", "port": "8000" }
Comments
Post a Comment