I am trying to setup a teamspeak 3 module for my WHMCS website.
I've did everything right according to the tutorial. But I also have an API coded in node that works with the module. When I access 0.0.0.0:3000 I get the error "Cannot GET /" My firewall is turned off so it can't be the any port that is blocked. This is my api.js
"use strict";
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('tsdns.sqlite');
var express = require('express');
var app = express();
var config = require('./config.json');
db.serialize(function() {
db.run("CREATE TABLE IF NOT EXISTS zones (id integer primary key, zone varchar(100),target varchar(50))");
});
app.get('/list', function (req, res) {
if( req.headers.authorization == config.api_key ){
var zone = req.params.zone;
db.all("SELECT * FROM zones", function(err, rows) {
res.send('{"result":"success","message":' + JSON.stringify( rows ) + '}');
});
}else{
res.statusCode = 403;
res.send('{"result":"error","message":"Invalid auth token"}');
}
});
app.get('/add/:zone/:target', function (req, res) {
if( req.headers.authorization == config.api_key ){
var zone = req.params.zone;
var target = req.params.target;
var sql = "INSERT INTO zones(zone,target) VALUES(?,?)";
var stmt = db.prepare(sql,zone,target);
stmt.run();
stmt.finalize();
res.statusCode = 201;
res.send('{result:"success"}');
}else{
res.statusCode = 403;
res.send('{"result":"error","message":"Invalid auth token"}');
}
});
app.get('/del/:zone', function (req, res) {
if( req.headers.authorization == config.api_key ){
var zone = req.params.zone;
var sql = "DELETE FROM zones WHERE zone =?";
var stmt = db.prepare(sql,zone);
stmt.run();
stmt.finalize();
res.statusCode = 202;
res.send('{result:"success"}');
}else{
res.statusCode = 403;
res.send('{"result":"error","message":"Invalid auth token"}');
}
});
app.get('/get/:zone', function (req, res) {
if( req.headers.authorization == config.api_key ){
var zone = req.params.zone;
db.all("SELECT * FROM zones WHERE zone=?",zone, function(err, row) {
res.statusCode = 200;
res.send('{"result":"success","message":' + JSON.stringify( row ) + '}');
});
}else{
res.statusCode = 403;
res.send('{"result":"error","message":"Invalid auth token"}');
}
});
module.exports = app;
And when I try to access e.g http://0.0.0.0:3000/list I get this error "{"result":"error","message":"Invalid auth token"}"
So something is obviously wrong. I am new to node so I can't figure out what the problem is.
This is my server.js
var config = require('./config.json');
var api = require('./api.js');
var tsdns = require('./tsdns');
api.listen(config.api_port,config.api_ip, function () {
console.log('Api webservice running at %s:%s', config.api_ip, config.api_port);
});
tsdns.listen(config.tsdns_port,config.tsdns_ip, function () {
console.log('Tsdns running at %s:%s', config.tsdns_ip,config.tsdns_port);
});
That is what I am supposed to start when I want the API to run and then it says this.
C:\Users\Administrator>node server.js Api webservice running at 0.0.0.0:3000 Tsdns running at 0.0.0.0:41144
So it says it is running and I don't recieve any errors, this API doesn't have any error logs either. This is the API folder CLICK HERE TO SEE IT
If you want me to share more codes of the API then I will.