switched to imports, debugged sessions
This commit is contained in:
@@ -1,44 +1,59 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
const p42apiConfig = require("./p42api.json");
|
||||
const http = require('http');
|
||||
const express = require("express");
|
||||
const bodyParser = require('body-parser');
|
||||
const session = require('express-session')
|
||||
const MySQLStore = require('express-mysql-session')(session);
|
||||
import p42apiConfig from './p42api.json' with { type: 'json' }
|
||||
import mysql from 'mysql2/promise'
|
||||
import http from 'http'
|
||||
import express from 'express'
|
||||
import session from 'express-session'
|
||||
import connectMySQL from 'express-mysql-session'
|
||||
import { corsResolver } from './corsMiddleware.js'
|
||||
import { P42ApiEndpoints } from './p42ApiEndpoints.js'
|
||||
|
||||
const corsResolver = require('./corsMiddleware')
|
||||
const P42ApiEndpoints = require('./p42ApiEndpoints')
|
||||
const MySQLStore = connectMySQL(session)
|
||||
|
||||
const app = express();
|
||||
app.set('trust proxy', 1) // trust first proxy (nginx), so we serve http to nginx, but we still behave as if we're in https
|
||||
app.use(express.json())
|
||||
app.use(corsResolver)
|
||||
|
||||
//TOTO: kick this
|
||||
const mysqlCreds = {
|
||||
// host: '127.0.0.1',
|
||||
// port: 3306,
|
||||
socketPath: '/var/run/mysqld/mysqld.sock',
|
||||
user: 'p42',
|
||||
password: 'C3h=V9!r>Mvc>skxPf9?W2P3duJTk',
|
||||
database: 'p42'
|
||||
database: 'p42',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
}
|
||||
|
||||
const sessionStore = new MySQLStore({ ...mysqlCreds,
|
||||
|
||||
const db = await mysql.createConnection(mysqlCreds)
|
||||
// {
|
||||
// host: mysqlCreds.host,
|
||||
// port: mysqlCreds.port,
|
||||
// socketPath: mysqlCreds.socketPath,
|
||||
// database: mysqlCreds.database,
|
||||
// user: mysqlCreds.user,
|
||||
// password: mysqlCreds.password
|
||||
// });
|
||||
|
||||
const sessionStore = new MySQLStore({
|
||||
createDatabaseTable: false,
|
||||
clearExpired: true,
|
||||
schema: {
|
||||
tableName: 'p42_sessions',
|
||||
columnNames: {
|
||||
session_id: 'session_id',
|
||||
expires: 'expires',
|
||||
data: 'data'
|
||||
}
|
||||
}
|
||||
});
|
||||
tableName: 'p42_sessions',
|
||||
columnNames: {
|
||||
session_id: 'session_id',
|
||||
expires: 'expires',
|
||||
data: 'data'
|
||||
}
|
||||
}
|
||||
}, db)
|
||||
|
||||
|
||||
const app = express();
|
||||
app.set('trust proxy', 1) // trust first proxy (nginx), so we serve http to nginx, but we still behave as if we're in https
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
app.use(bodyParser.json())
|
||||
app.use(corsResolver);
|
||||
|
||||
app.use(session({
|
||||
name: 'p42.api.sid',
|
||||
secret: 'qNhy555Y9vyxj?!3yaYA=aKfgk+Wy5eymNtP*?4i',
|
||||
@@ -53,8 +68,8 @@ app.use(session({
|
||||
}
|
||||
))
|
||||
|
||||
let eps = new P42ApiEndpoints(app)
|
||||
eps.connectDB(mysqlCreds)
|
||||
|
||||
let eps = new P42ApiEndpoints(app, db)
|
||||
|
||||
const server = http.createServer(app)
|
||||
.listen(p42apiConfig.listenPort, p42apiConfig.listenHost, function (req, res) {
|
||||
|
||||
Reference in New Issue
Block a user