123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import express from 'express'
- import path from 'path'
- import morgan from 'morgan'
- import socketio from 'socket.io'
- import db from './db'
- const pg = require('pg')
- delete pg.native
- const {connectUpstream} = require('./joystream/ws')
- const { addBlockRange } = require('./joystream')
- const {setupSocket} = require('./socket')
- const PORT: number = process.env.PORT ? +process.env.PORT : 3500
- const app = express()
- const server = app.listen(PORT, () => {
- console.log(`[Express] Listening on port ${PORT}`)
- });
- (async () =>{
- const api = await connectUpstream()
- const io: any = socketio(server)
- setupSocket(io, api)
- const args = process.argv.slice(2);
- if (args.length === 2){
- const startBlock = args[0];
- const endBlock = args[1];
- console.log(`[Joystream] syncing blocks from ${startBlock} to ${endBlock}`);
- addBlockRange(api, startBlock, endBlock);
- }
- })()
- //const cors = require("cors");
- //const passport = require('passport')
- //const LocalStrategy = require('passport-local')
- //const session = require('express-session')
- //const SequelizeStore = require('connect-session-sequelize')(session.Store)
- //const sessionStore = new SequelizeStore({ db })
- app.use(morgan('dev'))
- //app.use(cors({ credentials: true, origin: URL }))
- // passport.use(
- // new LocalStrategy(async (username, password, done) => {
- // const user = await db.models.user.findOne({ where: { username } })
- // if (!user) {
- // return done(null, false, { message: 'Incorrect username.' })
- // }
- // if (!user.correctPassword(password)) {
- // return done(null, false, { message: 'Incorrect password.' })
- // }
- // return done(null, user)
- // })
- // )
- //passport.serializeUser((user, cb) => cb(null, user.id))
- // passport.deserializeUser(async (id, cb) => {
- // try {
- // const user = await db.models.user.findByPk(id)
- // if (!user) return cb(null, { id: 0 })
- // const idType = user.isAdmin ? 'trainerId' : 'userId'
- // const { sessions, reviews, notes, referrers } = await user.fetchMyData(
- // idType
- // )
- // user.setDataValue('sessions', sessions)
- // user.setDataValue('reviews', reviews)
- // user.setDataValue('notes', notes)
- // user.setDataValue('referrers', referrers)
- // cb(null, user)
- // } catch (err) {
- // console.log('error', err)
- // cb(err)
- // }
- // })
- // app.use(
- // session({
- // secret: process.env.SESSION_SECRET || 'LAKaLIHWIUH9*&h3ISVAEOIUFHAW83w',
- // store: sessionStore,
- // resave: false,
- // saveUninitialized: false,
- // cookie: { maxAge: 3600000 },
- // })
- // )
- //
- // app.use(passport.initialize())
- // app.use(passport.session())
- // body parsing middleware
- app.use(express.json())
- app.use(express.urlencoded({ extended: true }))
- app.use(require('body-parser').text())
- //app.use("/api", require("./api"));
- //app.use('/auth', require('./auth'))
- app.use(
- '/static',
- express.static(path.resolve(__dirname, '..', 'build', 'static'))
- )
- app.get('/manifest.json', (req: any, res: any) => {
- res.sendFile(path.resolve(__dirname, '..', 'build', 'manifest.json'))
- })
- app.get('/favicon.png', (req: any, res: any) => {
- res.sendFile(path.resolve(__dirname, '..', 'build', 'favicon.png'))
- })
- app.use('*', express.static(path.resolve(__dirname, '..', 'build')))
- // error handling endware
- app.use((err: any, req: any, res: any, next: any) => {
- console.error(err)
- console.error(err.stack)
- res.status(err.status || 500).send(err.message || 'Internal server error.')
- next()
- })
- //module.exports = {}
- //export {}
|