swap requires to imports
This commit is contained in:
+4
-3
@@ -1,5 +1,5 @@
|
||||
require('dotenv').config();
|
||||
const { Pool } = require('pg');
|
||||
import 'dotenv/config';
|
||||
import { Pool } from 'pg';
|
||||
|
||||
const pool = new Pool
|
||||
({
|
||||
@@ -105,7 +105,8 @@ async function ensureOauthClient(provider, client_id, client_secret, redirect_ur
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export
|
||||
{
|
||||
waitForDb,
|
||||
createTables,
|
||||
query,
|
||||
|
||||
@@ -5,9 +5,6 @@ WORKDIR /app
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
RUN npm install passport
|
||||
RUN npm install passport-github2
|
||||
RUN npm install express-session
|
||||
|
||||
COPY . .
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const express = require('express');
|
||||
const http = require('http');
|
||||
const cors = require('cors');
|
||||
const {Server} = require('socket.io');
|
||||
const authRouter = require('./routes/auth');
|
||||
const chatRouter = require('./routes/global_chat');
|
||||
const {waitForDb, createTables, ensureOauthClient} = require('./db');
|
||||
const setupSocketIO = require('./services/socket');
|
||||
import express from 'express';
|
||||
import http from 'http';
|
||||
import cors from 'cors';
|
||||
import {Server} from 'socket.io';
|
||||
import authRouter from './routes/auth.js';
|
||||
import chatRouter from './routes/global_chat.js';
|
||||
import {waitForDb, createTables, ensureOauthClient} from './db.js';
|
||||
import setupSocketIO from './services/socket.js';
|
||||
|
||||
const app = express();
|
||||
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;
|
||||
if (!header)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"type": "module",
|
||||
"dependencies":
|
||||
{
|
||||
"express": "^4.18.2",
|
||||
@@ -7,6 +8,9 @@
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"dotenv": "^17.2.3",
|
||||
"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 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) =>
|
||||
{
|
||||
@@ -65,7 +67,6 @@ router.get('/github/callback', async (req, res) => {
|
||||
if (result.rows.length > 0) {
|
||||
userId = result.rows[0].id;
|
||||
} else {
|
||||
const crypto = require('crypto');
|
||||
const randomPwd = crypto.randomBytes(16).toString('hex');
|
||||
const passwordHash = await bcrypt.hash(randomPwd, 10);
|
||||
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 chatService = require('../services/global_chat');
|
||||
const authenticateToken = require('../middleware/auth');
|
||||
|
||||
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');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const {query} = require('../db');
|
||||
import bcrypt from 'bcrypt';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import {query} from '../db.js';
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -24,8 +24,4 @@ async function getRecentMessages(limit = 50)
|
||||
return (result.rows.reverse());
|
||||
}
|
||||
|
||||
module.exports =
|
||||
{
|
||||
saveMessage,
|
||||
getRecentMessages
|
||||
};
|
||||
export default {saveMessage, getRecentMessages};
|
||||
@@ -1,5 +1,5 @@
|
||||
const jwt = require('jsonwebtoken');
|
||||
const chatService = require('./global_chat');
|
||||
import jwt from 'jsonwebtoken';
|
||||
import chatService from './global_chat.js';
|
||||
|
||||
function setupSocketIO(io)
|
||||
{
|
||||
@@ -44,4 +44,4 @@ function setupSocketIO(io)
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = setupSocketIO;
|
||||
export default setupSocketIO;
|
||||
Reference in New Issue
Block a user