You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5 KiB

import http from 'http';
import dotenv from 'dotenv'
import path from 'path'
import express, { Request, Response } from 'express';
import bodyParser from 'body-parser'
import cookieParser from 'cookie-parser'
import session from 'express-session'
import redis from 'redis'
import connectRedis from 'connect-redis'
// import passport from 'passport';
import register from '@react-ssr/express/register';
dotenv.config({ path: path.join(__dirname, '../.env') });
const SECRET = 'secret'
const RedisStore = connectRedis(session);
const redisClient = redis.createClient({
host: '127.0.0.1',
port: 6379,
password: process.env.REDIS_PASSWORD
})
redisClient.on('error', (error) => {
console.error(error);
});
redisClient.on('connect', () => {
console.log('Connection to Redis has been established successfully.');
});
const app = express();
app.set('trust proxy', 1);
const server = http.createServer(app);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser(SECRET));
app.use(
session({
store: new RedisStore({ client: redisClient }),
secret: SECRET,
resave: false,
saveUninitialized: false,
})
);
// initPassport();
// app.use(passport.initialize());
(async () => {
await register(app);
app.get('/', (_req: Request, res: Response) => {
const user = { name: 'World' };
res.render('index', { user });
});
server.listen(3000, () => {
console.log('> Ready on http://localhost:3000');
});
})();