Compare commits
2 Commits
e4c038c940
...
1.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
| a197d9bd3b | |||
| 91cdc9e08a |
4
index.js
4
index.js
@@ -4,9 +4,11 @@ import express from "express";
|
|||||||
import expressWs from "express-ws";
|
import expressWs from "express-ws";
|
||||||
import morgan from "morgan";
|
import morgan from "morgan";
|
||||||
import cookieParser from "cookie-parser";
|
import cookieParser from "cookie-parser";
|
||||||
|
import cors from "cors";
|
||||||
import { initWebsocket } from "./src/websocket.js";
|
import { initWebsocket } from "./src/websocket.js";
|
||||||
import { initAuth } from "./src/auth.js";
|
import { initAuth } from "./src/auth.js";
|
||||||
import { close as closeDbConnection, initDbConnection, db } from "./src/db.js";
|
import { close as closeDbConnection, initDbConnection, db } from "./src/db.js";
|
||||||
|
import { initUsers } from "./src/user.js";
|
||||||
const app = express();
|
const app = express();
|
||||||
const appWs = expressWs(app);
|
const appWs = expressWs(app);
|
||||||
const port = 12345;
|
const port = 12345;
|
||||||
@@ -17,6 +19,7 @@ process.on('exit', function() {
|
|||||||
closeDbConnection();
|
closeDbConnection();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(cors({credentials: true, origin: process.env.JEOPARDY_URL}));
|
||||||
app.use(morgan(process.env.production ? 'common' : 'dev'));
|
app.use(morgan(process.env.production ? 'common' : 'dev'));
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
@@ -24,6 +27,7 @@ app.use(cookieParser());
|
|||||||
await initDbConnection();
|
await initDbConnection();
|
||||||
|
|
||||||
initAuth(app, db);
|
initAuth(app, db);
|
||||||
|
initUsers(app);
|
||||||
initWebsocket(app);
|
initWebsocket(app);
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
|
|||||||
27
package-lock.json
generated
27
package-lock.json
generated
@@ -1,16 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "jeopardyserver",
|
"name": "jeopardyserver",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "jeopardyserver",
|
"name": "jeopardyserver",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/express": "^5.0.3",
|
"@types/express": "^5.0.3",
|
||||||
"cookie-parser": "^1.4.7",
|
"cookie-parser": "^1.4.7",
|
||||||
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"express": "^5.1.0",
|
"express": "^5.1.0",
|
||||||
"express-ws": "^5.0.2",
|
"express-ws": "^5.0.2",
|
||||||
@@ -298,6 +299,19 @@
|
|||||||
"node": ">=6.6.0"
|
"node": ">=6.6.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/cors": {
|
||||||
|
"version": "2.8.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||||
|
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"object-assign": "^4",
|
||||||
|
"vary": "^1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.4.3",
|
"version": "4.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
||||||
@@ -834,6 +848,15 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/object-assign": {
|
||||||
|
"version": "4.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||||
|
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/object-inspect": {
|
"node_modules/object-inspect": {
|
||||||
"version": "1.13.4",
|
"version": "1.13.4",
|
||||||
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
|
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "jeopardyserver",
|
"name": "jeopardyserver",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"author": "",
|
"author": "",
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/express": "^5.0.3",
|
"@types/express": "^5.0.3",
|
||||||
"cookie-parser": "^1.4.7",
|
"cookie-parser": "^1.4.7",
|
||||||
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"express": "^5.1.0",
|
"express": "^5.1.0",
|
||||||
"express-ws": "^5.0.2",
|
"express-ws": "^5.0.2",
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ export function initAuth(app, db) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkSessionToken(req, res, next) {
|
async function checkSessionToken(req, res, next) {
|
||||||
|
|
||||||
if (req.path.startsWith("/auth/")) {
|
if (req.path.startsWith("/auth/")) {
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
@@ -52,7 +51,8 @@ async function loginUser(req, res) {
|
|||||||
expires.setDate(expires.getDate() + 1);
|
expires.setDate(expires.getDate() + 1);
|
||||||
|
|
||||||
res.cookie('jeopardytoken', sessiontoken, {
|
res.cookie('jeopardytoken', sessiontoken, {
|
||||||
maxAge: 1e3 * 60 * 60 * 24
|
maxAge: 1e3 * 60 * 60 * 24,
|
||||||
|
path: "/"
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).send(username);
|
res.status(200).send(username);
|
||||||
|
|||||||
9
src/user.js
Normal file
9
src/user.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
export function initUsers(app) {
|
||||||
|
app.get('/user/username', returnUsername);
|
||||||
|
}
|
||||||
|
|
||||||
|
function returnUsername(req, res) {
|
||||||
|
res.status(200).send(req.user.username);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user