devslopes-learn / mac-chat-api Goto Github PK
View Code? Open in Web Editor NEWPrebuilt api for slack app clone.
Prebuilt api for slack app clone.
I have already successfully deployed api on heroku but i am not able to get response from heroku in application. I am getting this type of response when i am trying to register user.
po response.result.value โฟ Optional<String> - some : "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf- 8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot POST /account/register</pre>\n</body>\n</html>\n"
Help me with this issue please .
I hope someone will respond. I know I'm behind a little, but I'm going through the iOS 11 course, and want to finish it before going to iOS 12. I'm finishing "Networking API and Building a Slack Clone" and got to the "Sockets and Messages". I've double checked the code and repeat it a couple of times after JonnyB, but my messages are not coming back from the server after I send them. I've put a breakpoint in the "func getChatMessage" where we should get data from the "dataArray" and this breakpoint was never triggered. It tells me that the server doesn't emit messages, or event is called differently now. I'm using "messageCreated" event as in the video.
Please advise
When I do this on my Kotlin Activity :
socket.emit("newChannel",channelName,channelDesc)
I don't see any channel getting created on mongo as shown in the tutorial. Nor any log on Heroku such as : new channel created . However I do get :
a user connected
at=info method=GET path="/socket.io/?EIO=4&transport=polling" host=herokumongodbsmackchat.herokuapp.com request_id=61a72504-c0ae-439f-9f75-228d3aae7a6b fwd="100.100.000.000" dyno=web.1 connect=1ms service=5ms status=200 bytes=328 protocol=https
Here's my index.js api code :
import http from 'http';
import express from 'express';
import bodyParser from 'body-parser';
import passport from 'passport';
import socket from 'socket.io';
import Message from './model/message';
import Channel from './model/channel';
const LocalStrategy = require('passport-local').Strategy;
import config from './config';
import routes from './routes';
let app = express();
app.server = http.createServer(app);
let io = socket(app.server);
//middleware
//parse application/json
app.use(bodyParser.json({
limit: config.bodyLimit
}));
//passport config
app.use(passport.initialize());
let Account = require('./model/account');
passport.use(new LocalStrategy({
usernameField: 'email',
passwordField: 'password'
},
Account.authenticate()
));
passport.serializeUser(Account.serializeUser());
passport.deserializeUser(Account.deserializeUser());
//api routes v1
app.use('/v1', routes);
// Base URL test endpoint to see if API is running
app.get('/', (req, res) => {
res.json({ message: 'Chat API is ALIVE!' })
});
/*||||||||||||||||SOCKET|||||||||||||||||||||||*/
//Listen for connection
var typingUsers = {};
io.on('connection', function(client) {
console.log('a user connected');
//Listens for a new chat message
client.on('newChannel', function(name, description) {
//Create channel
let newChannel = new Channel({
name: name,
description: description,
});
//Save it to database
newChannel.save(function(err, channel){
//Send message to those connected in the room
console.log('new channel created');
io.emit("channelCreated", channel.name, channel.description, channel.id);
});
});
//Listens for user typing.
client.on("startType", function(userName, channelId){
console.log("User " + userName + " is writing a message...");
typingUsers[userName] = channelId;
io.emit("userTypingUpdate", typingUsers, channelId);
});
client.on("stopType", function(userName){
console.log("User " + userName + " has stopped writing a message...");
delete typingUsers[userName];
io.emit("userTypingUpdate", typingUsers);
});
//Listens for a new chat message
client.on('newMessage', function(messageBody, userId, channelId, userName, userAvatar, userAvatarColor) {
//Create message
console.log(messageBody);
let newMessage = new Message({
messageBody: messageBody,
userId: userId,
channelId: channelId,
userName: userName,
userAvatar: userAvatar,
userAvatarColor: userAvatarColor
});
//Save it to database
newMessage.save(function(err, msg){
//Send message to those connected in the room
console.log('new message sent');
io.emit("messageCreated", msg.messageBody, msg.userId, msg.channelId, msg.userName, msg.userAvatar, msg.userAvatarColor, msg.id, msg.timeStamp);
});
});
});
/*||||||||||||||||||||END SOCKETS||||||||||||||||||*/
app.server.listen(config.port);
console.log(`Started on port ${app.server.address().port}`);
module.exports = {
app,
io
}
Edit-2 : I used a different library for Socket communication and I didn't send the proper parameters.
used : 'com.github.nkzawa:socket.io-client:0.6.0' . Rest of the steps are same as the one in the JohnnyB's tutorial
Hi, the request for "add/user" returns success but when i try to fetch name,avatarColor,avatarName the response doesn't have then and only have __v, _id fields and also same when i look at the mlab table User object has only 2 fields
Can we Edit this api to upload profile photo in the place of avatar picker. because i need this
I have enrolled in the android course on Kotlin by JonnyB on Udemy. While local hosting the app I am not able to send the PUT request via Postman. "Could not send request" appears every time I try to send the request. I have connected my MongoDB with localhost.
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
When you execute npm install locally, it installs the latest version of mongoose. The newest version of it has breaking changes. Mongoose should be set to "4.9.7", unless you want to refactor your code to accommodate the changes.
Hello , please I need help , because I can go further in the Kotlin course,
In fact, after I followed all the steps exactly as mentionned by JohnnyB, when I want to start the app in Heroku I get this erro , (I am using the free way, without a credit card )
Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail
> [email protected] dev C:\prem\work\DataBase\mac-chat-api
> NODE_ENV=development nodemon -w src --exec "babel-node src --presets es2015,stage-0"
'NODE_ENV' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev:
NODE_ENV=development nodemon -w src --exec "babel-node src --presets es2015,stage-0"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\myUserName\AppData\Roaming\npm-cache\_logs\2018-04-13T20_21_07_648Z-debug.log
Getting the following error if I try to register a user twice.
_http_outgoing.js:503
throw new errors.Error('ERR_HTTP_HEADERS_SENT', 'set');
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at validateHeader (_http_outgoing.js:503:11)
at ServerResponse.setHeader (_http_outgoing.js:510:3)
at ServerResponse.header (/mnt/d/Developing/mac-chat-api/node_modules/express/lib/response.js:725:10)
at ServerResponse.send (/mnt/d/Developing/mac-chat-api/node_modules/express/lib/response.js:170:12)
at /mnt/d/Developing/mac-chat-api/src/controller/account.js:28:31
at complete (/mnt/d/Developing/mac-chat-api/node_modules/passport/lib/middleware/authenticate.js:250:13)
at /mnt/d/Developing/mac-chat-api/node_modules/passport/lib/middleware/authenticate.js:257:15
at pass (/mnt/d/Developing/mac-chat-api/node_modules/passport/lib/authenticator.js:421:14)
at Authenticator.transformAuthInfo (/mnt/d/Developing/mac-chat-api/node_modules/passport/lib/authenticator.js:443:5)
at /mnt/d/Developing/mac-chat-api/node_modules/passport/lib/middleware/authenticate.js:254:22
at IncomingMessage.req.login.req.logIn (/mnt/d/Developing/mac-chat-api/node_modules/passport/lib/http/request.js:63:13)
at Strategy.strategy.success (/mnt/d/Developing/mac-chat-api/node_modules/passport/lib/middleware/authenticate.js:235:13)
at verified (/mnt/d/Developing/mac-chat-api/node_modules/passport-local/lib/strategy.js:83:10)
at PBKDF2.ondone (/mnt/d/Developing/mac-chat-api/node_modules/passport-local-mongoose/index.js:152:16)
Postman returns:
{
"message": {
"name": "UserExistsError",
"message": "A user with the given username is already registered"
}
}
if the following POST is sent multiple times to http://localhost:3005/v1/account/register
:
{
"email": "[email protected]",
"password": "123456"
}
I have enrolled in the android course on Kotlin by JonnyB on Udemy. I am facing an issue while deploying the app to heroku. When I Open App, Application Error window appears. Please tell how to fix this. Thanks in advance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.