Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
2.4 kB
0
Indexable
Never
const express = require('express')
const path = require('path')
const cookieParser = require('cookie-parser')
const logger = require('morgan')
const swaggerUI = require('swagger-ui-express')

const cors = require('cors')
const session = require('express-session')

const indexRouter = require('./routes/index')
const userRouter = require('./routes/user')
const orderRouter = require('./routes/order')
const productRouter = require('./routes/product')
const transportRouter = require('./routes/transport')
const packageRouter = require('./routes/package')
const logisticRouter = require('./routes/logistic')
const walletRouter = require('./routes/wallet')
const storeRouter = require('./routes/store')
const destinationRouter = require('./routes/destination')
const vendorRouter = require('./routes/vendor')
const fileRouter = require('./routes/file')
const machineRouter = require('./routes/machine')
const couponRouter = require('./routes/coupon')
const policyRouter = require('./routes/policy')

const app = express()
const expressWs = require('express-ws')(app);
// expressWs(app)
const {walletSocket} = require('./routes/websocket')

app.ws('/walletWs', function (ws, req) {
  console.log('connect success')
  walletSocket(ws)
 
})

const swaggerDocs = require('./swagger.json')//swaggerJSDoc(swaggerOptions);
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerDocs));

app.set('trust proxy', 1) // trust first proxy
app.use(
    session({
        secret: 'Hsnl-iot33564@',
        resave: false,
        saveUninitialized: true,
        cookie: { secure: true, maxAge: 86400000 },
    })
)

app.use(cors())
app.use(logger('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(cookieParser())
app.use(express.static(path.join(__dirname, 'public')))
// app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerDocument))

// Modules
app.use('/', indexRouter)
app.use('/users', userRouter)
app.use('/vendor', vendorRouter)
app.use('/orders', orderRouter)
app.use('/transport', transportRouter)
app.use('/packages', packageRouter)
app.use('/products', productRouter)
app.use('/policy', policyRouter)
app.use('/logistics', logisticRouter)
app.use('/wallet', walletRouter)
app.use('/stores', storeRouter)
app.use('/destination', destinationRouter)
app.use('/files', fileRouter)
app.use('/machine',machineRouter)
app.use('/coupon',couponRouter)

// app.listen(8000)

module.exports = app