This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (51 loc) · 1.68 KB
/
index.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const express = require('express');
const app = express();
const handle = require('./src/handler');
const passport = require('passport');
const init = require('./src/passport');
const handler = new handle();
app.use(express.json());
app.use(passport.initialize());
init(passport);
/////////Message Server
//Post new message
app.post('/messages', passport.authenticate('jwt', { session: false }), (req, res, next) => {
handler.handleMessagePostRequest(req, res);
});
//Get unread message request
app.get('/messages', passport.authenticate('jwt', { session: false }), (req, res, next) => {
handler.handleMessageGetRequest(req, res);
});
//Get all message
app.get('/messagesAll', passport.authenticate('jwt', { session: false }), (req, res, next) => {
handler.handleMessagesGetAllRequest(req, res);
});
//Authentication
//Signup
app.post('/signup', (req, res) => {
handler.handleSignupRequest(req, res);
});
//Login
app.post('/login', passport.authenticate('local', { session: false }), (req, res, next) => {
handler.handleLoginRequest(req, res);
});
//Search for user by name
app.get('/names/:name',passport.authenticate('jwt', { session: false }),function(req,res){
handler.handleSearchRequestName(req, res);
});
//Extra request handles
//Setup page
app.get('/setup', (req, res) => {
res.sendFile('assets/setup.html', { root: __dirname });
});
//Home page
app.get('/', (req, res) => {
res.sendFile('assets/default.html', { root: __dirname });
});
//Redirect all unknown request to homepage.
app.all('*', (req, res) => {
res.redirect('/');
});
//Check port variable
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listen to port ${port}`));