|
|
|
@ -1,11 +1,12 @@
|
|
|
|
|
import 'regenerator-runtime/runtime';
|
|
|
|
|
import 'regenerator-runtime/runtime'
|
|
|
|
|
import path from 'path'
|
|
|
|
|
import dotenv from 'dotenv'
|
|
|
|
|
|
|
|
|
|
dotenv.config({ path: path.join(__dirname, '../.env') });
|
|
|
|
|
dotenv.config({ path: path.join(__dirname, '../.env') })
|
|
|
|
|
|
|
|
|
|
import http from 'http';
|
|
|
|
|
import express from 'express';
|
|
|
|
|
import http from 'http'
|
|
|
|
|
import express from 'express'
|
|
|
|
|
import proxy from 'express-http-proxy'
|
|
|
|
|
import bodyParser from 'body-parser'
|
|
|
|
|
import cookieParser from 'cookie-parser'
|
|
|
|
|
import session from 'express-session'
|
|
|
|
@ -15,66 +16,66 @@ import connectRedis from 'connect-redis'
|
|
|
|
|
import passport from 'passport'
|
|
|
|
|
import mongoose from 'mongoose'
|
|
|
|
|
|
|
|
|
|
import { authRouter, initPassport } from './auth/passport';
|
|
|
|
|
import ensureAuthenticated from './auth/middleware';
|
|
|
|
|
import { authRouter, initPassport } from './auth/passport'
|
|
|
|
|
|
|
|
|
|
const RedisStore = connectRedis(session);
|
|
|
|
|
const RedisStore = connectRedis(session)
|
|
|
|
|
const redisClient = redis.createClient({
|
|
|
|
|
host: '127.0.0.1',
|
|
|
|
|
port: 6379,
|
|
|
|
|
password: process.env.REDIS_PASSWORD
|
|
|
|
|
password: process.env.REDIS_PASSWORD,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redisClient.on('error', (error) => {
|
|
|
|
|
console.error(error);
|
|
|
|
|
});
|
|
|
|
|
console.error(error)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redisClient.on('connect', () => {
|
|
|
|
|
console.log('Connection to Redis has been established successfully.');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mongoose.connect('mongodb://localhost:27017', {
|
|
|
|
|
useCreateIndex: true,
|
|
|
|
|
useNewUrlParser: true,
|
|
|
|
|
useUnifiedTopology: true,
|
|
|
|
|
user: process.env.MONGODB_USER,
|
|
|
|
|
pass: process.env.MONGODB_PASSWORD,
|
|
|
|
|
dbName: 'museum'
|
|
|
|
|
}, () => {
|
|
|
|
|
console.log('Connection to MongoDB has been established successfully.')
|
|
|
|
|
console.log('Connection to Redis has been established successfully.')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
|
app.set('trust proxy', 1);
|
|
|
|
|
const server = http.createServer(app);
|
|
|
|
|
mongoose.connect(
|
|
|
|
|
'mongodb://localhost:27017',
|
|
|
|
|
{
|
|
|
|
|
useCreateIndex: true,
|
|
|
|
|
useNewUrlParser: true,
|
|
|
|
|
useUnifiedTopology: true,
|
|
|
|
|
user: process.env.MONGODB_USER,
|
|
|
|
|
pass: process.env.MONGODB_PASSWORD,
|
|
|
|
|
dbName: 'museum',
|
|
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
console.log('Connection to MongoDB 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(process.env.SESSION_SECRET));
|
|
|
|
|
app.use(bodyParser.json())
|
|
|
|
|
app.use(bodyParser.urlencoded({ extended: false }))
|
|
|
|
|
app.use(cookieParser(process.env.SESSION_SECRET))
|
|
|
|
|
app.use(
|
|
|
|
|
session({
|
|
|
|
|
store: new RedisStore({ client: redisClient }),
|
|
|
|
|
secret: process.env.SESSION_SECRET,
|
|
|
|
|
resave: false,
|
|
|
|
|
saveUninitialized: false,
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
app.use(passport.initialize());
|
|
|
|
|
app.use(passport.session());
|
|
|
|
|
initPassport();
|
|
|
|
|
app.use('/auth', authRouter);
|
|
|
|
|
app.use(passport.initialize())
|
|
|
|
|
app.use(passport.session())
|
|
|
|
|
initPassport()
|
|
|
|
|
app.use('/auth', authRouter)
|
|
|
|
|
|
|
|
|
|
app.use(express.static(path.resolve(__dirname, '../static')));
|
|
|
|
|
|
|
|
|
|
app.get('/', (_req, res) => {
|
|
|
|
|
res.render('index');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.get('/museo', ensureAuthenticated, (req, res) => {
|
|
|
|
|
res.render('museo', { user: req.user })
|
|
|
|
|
});
|
|
|
|
|
if (process.env.NODE_ENV !== 'PRODUCTION') {
|
|
|
|
|
const proxy = require('express-http-proxy')
|
|
|
|
|
app.use('/', proxy('http://localhost:4000/'))
|
|
|
|
|
} else {
|
|
|
|
|
// probably serve up build version in production
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server.listen(3000, () => {
|
|
|
|
|
console.log('> Ready on http://localhost:3000');
|
|
|
|
|
});
|
|
|
|
|
console.log('> Ready on http://localhost:3000')
|
|
|
|
|
})
|
|
|
|
|