-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (26 loc) · 962 Bytes
/
server.js
File metadata and controls
32 lines (26 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const express = require("express");
const app = express()
const cors = require("cors");
const { default: axios } = require("axios");
app.use(express.json());
app.use(cors({origin:true}));
app.post("/authenticate", async(req, res)=>{
const {username} = req.body || {}
try {
const response = await axios.put(
"https://api.chatengine.io/users/",
{username:username, secret:username, first_name:username},
{headers: {"private-key":"6776936a-4abf-4370-9b5b-f380e6712068"}}
);
return res.status(response.status).json(response.data)
} catch (e) {
if (e.response) {
return res.status(e.response.status).json(e.response.data)
} else {
res.status(500).json({message:"Internal server error"})
}
}
});
// "https://api.chatengine.io/users/"
// "6776936a-4abf-4370-9b5b-f380e6712068"
app.listen(3001);