Browse Source

/api --> api

pull/1/head
Senta Mandutz 5 years ago
parent
commit
e12bd98dbb
3 changed files with 8 additions and 8 deletions
  1. 1
    1
      public/createMessage.js
  2. 2
    2
      public/home.js
  3. 5
    5
      server.js

+ 1
- 1
public/createMessage.js View File

var tag=$("#tag").val(); var tag=$("#tag").val();
var user=$("#user").val(); var user=$("#user").val();
console.log ("Message Created: "+tag+" "+message+" "+user); console.log ("Message Created: "+tag+" "+message+" "+user);
$.ajax ({ url: "/api/createMsg", data: {sub: subject, mess: message, use: user, ta: tag}, method: "POST" }) .done (have_result) .fail (have_error);
$.ajax ({ url: "api/createMsg", data: {sub: subject, mess: message, use: user, ta: tag}, method: "POST" }) .done (have_result) .fail (have_error);
function have_result (res) { function have_result (res) {
console.log (res); console.log (res);
} }

+ 2
- 2
public/home.js View File

}); });
},*/ },*/
list_messages: function () { list_messages: function () {
$.ajax({url: "/api/ids", method: "GET"})
$.ajax({url: "api/ids", method: "GET"})
.done(jd => { .done(jd => {
// NICHT SO wg. Vue: _messagelist = jd; // NICHT SO wg. Vue: _messagelist = jd;
_messagelist.splice(0, _messagelist.length); _messagelist.splice(0, _messagelist.length);
}; };


function get_insert_message(id) { function get_insert_message(id) {
$.ajax({ url: "/api/msg/"+id, method: "GET" }).done(function (msg) {
$.ajax({ url: "api/msg/"+id, method: "GET" }).done(function (msg) {
Vue.set(_messages, id, msg); Vue.set(_messages, id, msg);
}).fail(function (e, f, g) { }).fail(function (e, f, g) {
console.log("cannot load " + id + ".json: " + e + f + g); console.log("cannot load " + id + ".json: " + e + f + g);

+ 5
- 5
server.js View File



//require('./app/routes/message.route.js')(app); //require('./app/routes/message.route.js')(app);


app.get ('/api/ids', function (req, res) {
app.get ('api/ids', function (req, res) {
Message.find({},{id: true}) .exec () .then(results => { Message.find({},{id: true}) .exec () .then(results => {
//selects id from message: //selects id from message:
var parsed = []; var parsed = [];
}); });
}); });


app.get ("/api/msg/:id", function (req, res) {
app.get ("api/msg/:id", function (req, res) {
Message.findOne ({_id: req.params.id}) .exec (function (err, results){ Message.findOne ({_id: req.params.id}) .exec (function (err, results){
if (err) { if (err) {
console.log (err); console.log (err);
}); });
}); });


function makeid() {
/*function makeid() {
var text = ""; var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";


text += possible.charAt(Math.floor(Math.random() * possible.length)); text += possible.charAt(Math.floor(Math.random() * possible.length));


return text; return text;
}
}*/


app.post("/api/createMsg", function(req, res){
app.post("api/createMsg", function(req, res){
//x = mongoose.Types.ObjectId(); //x = mongoose.Types.ObjectId();
//y = x.toString(); //y = x.toString();
//var z = makeid(); //var z = makeid();

Loading…
Cancel
Save