I want to publish a new layer in Geoserver. The layer seems unpublished and I get 'Undefined' error.
const publish = function () {
return new Promise((resolve, reject) => {
const layer = layerName
const workspace = workspaceName
const datastore = datastoreName
let body = `<featureType><name>${layer}</name>
<nativeBoundingBox>
<minx>-180</minx>
<maxx>180</maxx>
<miny>-90</miny>
<maxy>90</maxy>
<crs>EPSG:4326</crs>
</nativeBoundingBox>
<latLonBoundingBox>
<minx>-180</minx>
<maxx>180</maxx>
<miny>-90</miny>
<maxy>90</maxy>
<crs>EPSG:4326</crs>
</latLonBoundingBox>
</featureType>`
console.log('body length is ', body.length);
let options = {
url: `http://IP:port/geoserver/rest/workspaces/datastores/featuretypes.xml`,
method: 'POST',
headers: {
"Content-Type": "text.xml",
"Content-Length": body.length
},
auth: {
'user': 'user',
'pass': 'pass'
},
}
request(options, (err, resp, body) => {
if (!err && !body) {
return resolve()
} else if (!err) {
let message
if (resp.statusCode == 400) message = "layer not found"
else message = body
return reject({
status: 404,
errors: [{
messages: [message]
}]
})
} else {
return reject({
status: 500,
errors: [{
messages: ["ERRO: connection with geoserver"]
}]
})
}
})
})
}
publish().then(result => console.log(result))