-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (33 loc) · 1.25 KB
/
server.js
File metadata and controls
44 lines (33 loc) · 1.25 KB
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
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const jwt = require('jsonwebtoken');
const expressJwt = require('express-jwt');
var db = require('./models/db.js');
var user = require('./routes/user.js');
const jwtSecret = 'kjwdjs65$khikjl65nkajn';
const app = express();
//Port Number
app.port = 3000;
//Middlewares - bodyparser & cors
app.use(bodyParser.json());
app.use(cors());
//app.use('/login', expressJwt({ secret: jwtSecret }));
//Home Page Route
app.get("/", function(req, res){
res.sendfile(__dirname + '/client/views/index.html');
});
app.post('/signup',user.signup);
app.post('/login',user.login, function(req,res){
var token = jwt.sign({username: req.body.username}, jwtSecret);
res.status(200).send({token: token, username: req.body.username, highscore: req.body.highscore});
});
app.put("/setHighScore", user.updateHighScore);
app.use("/views", express.static(__dirname + "/client/views"));
app.use("/assets", express.static(__dirname + "/client/assets"));
app.use("/css", express.static(__dirname + "/client/css"));
app.use("/js", express.static(__dirname + "/client/js"));
//Start Server
app.listen(app.port, function(){
console.log("Server Started on Port Number: " + app.port);
});