mirror of
https://github.com/kaythomas0/noisedash.git
synced 2025-11-15 20:48:03 +00:00
Fix axios and server setup
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
const express = require('express')
|
||||
const session = require('express-session')
|
||||
const FileStore = require('session-file-store')(session)
|
||||
const cors = require('cors')
|
||||
const passport = require('passport')
|
||||
const path = require('path')
|
||||
const cookieParser = require('cookie-parser')
|
||||
const config = require('config')
|
||||
const authRouter = require('./routes/auth')
|
||||
const usersRouter = require('./routes/users')
|
||||
const profilesRouter = require('./routes/profiles')
|
||||
const app = express()
|
||||
const corsOptions = {
|
||||
origin: 'http://localhost:'.concat(config.get('Client.listeningPort')),
|
||||
credentials: true
|
||||
}
|
||||
const fileStoreOptions = {
|
||||
path: config.get('Server.sessionFileStorePath')
|
||||
}
|
||||
@@ -20,10 +16,12 @@ const fileStoreOptions = {
|
||||
require('./boot/db')()
|
||||
require('./boot/auth')()
|
||||
|
||||
app.use(cors(corsOptions))
|
||||
app.use(express.json())
|
||||
app.use(express.urlencoded({ extended: false }))
|
||||
app.use(cookieParser())
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
app.use(express.static(path.join(__dirname, '../dist')))
|
||||
}
|
||||
app.use(session({
|
||||
store: new FileStore(fileStoreOptions),
|
||||
secret: config.get('Server.sessionSecret'),
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
const app = require('../app')
|
||||
const debug = require('debug')('example:server')
|
||||
const fs = require('fs')
|
||||
@@ -10,9 +7,6 @@ const config = require('config')
|
||||
const tls = config.get('Server.tls')
|
||||
const http = require(tls ? 'https' : 'http')
|
||||
|
||||
/**
|
||||
* Get port from environment and store in Express.
|
||||
*/
|
||||
const port = normalizePort(config.get('Server.listeningPort'))
|
||||
app.set('port', port)
|
||||
|
||||
@@ -26,16 +20,10 @@ if (tls) {
|
||||
server = http.createServer(httpsOptions, app)
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen on provided port, on all network interfaces.
|
||||
*/
|
||||
server.listen(port)
|
||||
server.on('error', onError)
|
||||
server.on('listening', onListening)
|
||||
|
||||
/**
|
||||
* Normalize a port into a number, string, or false.
|
||||
*/
|
||||
function normalizePort (val) {
|
||||
const port = parseInt(val, 10)
|
||||
|
||||
@@ -52,9 +40,6 @@ function normalizePort (val) {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "error" event.
|
||||
*/
|
||||
function onError (error) {
|
||||
if (error.syscall !== 'listen') {
|
||||
throw error
|
||||
@@ -77,9 +62,6 @@ function onError (error) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "listening" event.
|
||||
*/
|
||||
function onListening () {
|
||||
const addr = server.address()
|
||||
const bind = typeof addr === 'string'
|
||||
|
||||
@@ -98,7 +98,7 @@ router.patch('/users/:userId', function (req, res) {
|
||||
return res.sendStatus(401)
|
||||
}
|
||||
|
||||
db.run('UPDATE users SET is_admin = ? WHERE id = ?', [req.body.isAdmin, req.params.userId], (err) => {
|
||||
db.run('UPDATE users SET is_admin = ? WHERE id = ?', [req.body.isAdmin ? 1 : 0, req.params.userId], (err) => {
|
||||
if (err) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user