swap requires to imports
This commit is contained in:
+4
-3
@@ -1,5 +1,5 @@
|
|||||||
require('dotenv').config();
|
import 'dotenv/config';
|
||||||
const { Pool } = require('pg');
|
import { Pool } from 'pg';
|
||||||
|
|
||||||
const pool = new Pool
|
const pool = new Pool
|
||||||
({
|
({
|
||||||
@@ -105,7 +105,8 @@ async function ensureOauthClient(provider, client_id, client_secret, redirect_ur
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export
|
||||||
|
{
|
||||||
waitForDb,
|
waitForDb,
|
||||||
createTables,
|
createTables,
|
||||||
query,
|
query,
|
||||||
|
|||||||
@@ -5,9 +5,6 @@ WORKDIR /app
|
|||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
RUN npm install
|
RUN npm install
|
||||||
RUN npm install passport
|
|
||||||
RUN npm install passport-github2
|
|
||||||
RUN npm install express-session
|
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
const express = require('express');
|
import express from 'express';
|
||||||
const http = require('http');
|
import http from 'http';
|
||||||
const cors = require('cors');
|
import cors from 'cors';
|
||||||
const {Server} = require('socket.io');
|
import {Server} from 'socket.io';
|
||||||
const authRouter = require('./routes/auth');
|
import authRouter from './routes/auth.js';
|
||||||
const chatRouter = require('./routes/global_chat');
|
import chatRouter from './routes/global_chat.js';
|
||||||
const {waitForDb, createTables, ensureOauthClient} = require('./db');
|
import {waitForDb, createTables, ensureOauthClient} from './db.js';
|
||||||
const setupSocketIO = require('./services/socket');
|
import setupSocketIO from './services/socket.js';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const jwt = require('jsonwebtoken');
|
import jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
module.exports = function authMiddleware(req, res, next)
|
export default function authMiddleware(req, res, next)
|
||||||
{
|
{
|
||||||
const header = req.headers.authorization;
|
const header = req.headers.authorization;
|
||||||
if (!header)
|
if (!header)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"type": "module",
|
||||||
"dependencies":
|
"dependencies":
|
||||||
{
|
{
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
@@ -7,6 +8,9 @@
|
|||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"socket.io": "^4.6.1",
|
"socket.io": "^4.6.1",
|
||||||
"cors": "^2.8.5"
|
"cors": "^2.8.5",
|
||||||
|
"passport": "0.7.0",
|
||||||
|
"passport-github2": "0.1.12",
|
||||||
|
"express-session": "1.18.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
const express = require('express');
|
import express from 'express';
|
||||||
|
import authService from '../services/auth.js';
|
||||||
|
import fetch from 'node-fetch';
|
||||||
|
import bcrypt from 'bcrypt';
|
||||||
|
import jwt from 'jsonwebtoken';
|
||||||
|
import {query} from '../db.js';
|
||||||
|
import crypto from 'crypto';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const authService = require('../services/auth');
|
|
||||||
const fetch = require('node-fetch');
|
|
||||||
const bcrypt = require('bcrypt');
|
|
||||||
const jwt = require('jsonwebtoken');
|
|
||||||
const {query} = require('../db');
|
|
||||||
|
|
||||||
router.post('/register', async(req, res) =>
|
router.post('/register', async(req, res) =>
|
||||||
{
|
{
|
||||||
@@ -65,7 +67,6 @@ router.get('/github/callback', async (req, res) => {
|
|||||||
if (result.rows.length > 0) {
|
if (result.rows.length > 0) {
|
||||||
userId = result.rows[0].id;
|
userId = result.rows[0].id;
|
||||||
} else {
|
} else {
|
||||||
const crypto = require('crypto');
|
|
||||||
const randomPwd = crypto.randomBytes(16).toString('hex');
|
const randomPwd = crypto.randomBytes(16).toString('hex');
|
||||||
const passwordHash = await bcrypt.hash(randomPwd, 10);
|
const passwordHash = await bcrypt.hash(randomPwd, 10);
|
||||||
await query(`INSERT INTO users (username, password_hash) VALUES ($1, $2)`, [ghUsername, passwordHash]);
|
await query(`INSERT INTO users (username, password_hash) VALUES ($1, $2)`, [ghUsername, passwordHash]);
|
||||||
@@ -84,4 +85,4 @@ router.get('/github/callback', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
export default router;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const express = require('express');
|
import express from 'express';
|
||||||
|
import chatService from '../services/global_chat.js';
|
||||||
|
import authenticateToken from '../middleware/auth.js';
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const chatService = require('../services/global_chat');
|
|
||||||
const authenticateToken = require('../middleware/auth');
|
|
||||||
|
|
||||||
router.get('/messages', authenticateToken, async(req, res) =>
|
router.get('/messages', authenticateToken, async(req, res) =>
|
||||||
{
|
{
|
||||||
@@ -17,4 +17,4 @@ router.get('/messages', authenticateToken, async(req, res) =>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
export default router;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
const bcrypt = require('bcrypt');
|
import bcrypt from 'bcrypt';
|
||||||
const jwt = require('jsonwebtoken');
|
import jwt from 'jsonwebtoken';
|
||||||
const {query} = require('../db');
|
import {query} from '../db.js';
|
||||||
|
|
||||||
async function login(username, password)
|
async function login(username, password)
|
||||||
{
|
{
|
||||||
@@ -60,4 +60,4 @@ async function register(username, password)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {register, login};
|
export default {register, login};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const {query} = require('../db');
|
import {query} from '../db.js';
|
||||||
|
|
||||||
async function saveMessage(userId, content)
|
async function saveMessage(userId, content)
|
||||||
{
|
{
|
||||||
@@ -24,8 +24,4 @@ async function getRecentMessages(limit = 50)
|
|||||||
return (result.rows.reverse());
|
return (result.rows.reverse());
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports =
|
export default {saveMessage, getRecentMessages};
|
||||||
{
|
|
||||||
saveMessage,
|
|
||||||
getRecentMessages
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
const jwt = require('jsonwebtoken');
|
import jwt from 'jsonwebtoken';
|
||||||
const chatService = require('./global_chat');
|
import chatService from './global_chat.js';
|
||||||
|
|
||||||
function setupSocketIO(io)
|
function setupSocketIO(io)
|
||||||
{
|
{
|
||||||
@@ -44,4 +44,4 @@ function setupSocketIO(io)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = setupSocketIO;
|
export default setupSocketIO;
|
||||||
Reference in New Issue
Block a user