mirror of
https://github.com/kaythomas0/noisedash.git
synced 2025-11-12 03:16:20 +00:00
Fix axios and server setup
This commit is contained in:
@@ -3,11 +3,8 @@
|
|||||||
"listeningPort": 3000,
|
"listeningPort": 3000,
|
||||||
"sessionFileStorePath": "./sessions",
|
"sessionFileStorePath": "./sessions",
|
||||||
"sessionSecret": "cats",
|
"sessionSecret": "cats",
|
||||||
"tls": true,
|
"tls": false,
|
||||||
"tlsKey": "./certs/key.pem",
|
"tlsKey": "./certs/key.pem",
|
||||||
"tlsCert": "./certs/cert.pem"
|
"tlsCert": "./certs/cert.pem"
|
||||||
},
|
|
||||||
"Client": {
|
|
||||||
"listeningPort": 8080
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17153
package-lock.json
generated
17153
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "vue-cli-service serve",
|
"serve": "vue-cli-service serve",
|
||||||
"server": "node server/bin/www.js",
|
"server": "node server/bin/www.js",
|
||||||
|
"server-prod": "NODE_ENV=production node server/bin/www.js",
|
||||||
"build": "vue-cli-service build",
|
"build": "vue-cli-service build",
|
||||||
"lint": "vue-cli-service lint"
|
"lint": "vue-cli-service lint"
|
||||||
},
|
},
|
||||||
@@ -13,11 +14,11 @@
|
|||||||
"config": "^3.3.6",
|
"config": "^3.3.6",
|
||||||
"cookie-parser": "^1.4.5",
|
"cookie-parser": "^1.4.5",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"cors": "^2.8.5",
|
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-session": "^1.17.2",
|
"express-session": "^1.17.2",
|
||||||
"passport": "^0.4.1",
|
"passport": "^0.4.1",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
|
"path": "^0.12.7",
|
||||||
"session-file-store": "^1.5.0",
|
"session-file-store": "^1.5.0",
|
||||||
"sqlite3": "^5.0.2",
|
"sqlite3": "^5.0.2",
|
||||||
"tone": "^14.7.77",
|
"tone": "^14.7.77",
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
const session = require('express-session')
|
const session = require('express-session')
|
||||||
const FileStore = require('session-file-store')(session)
|
const FileStore = require('session-file-store')(session)
|
||||||
const cors = require('cors')
|
|
||||||
const passport = require('passport')
|
const passport = require('passport')
|
||||||
|
const path = require('path')
|
||||||
const cookieParser = require('cookie-parser')
|
const cookieParser = require('cookie-parser')
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
const authRouter = require('./routes/auth')
|
const authRouter = require('./routes/auth')
|
||||||
const usersRouter = require('./routes/users')
|
const usersRouter = require('./routes/users')
|
||||||
const profilesRouter = require('./routes/profiles')
|
const profilesRouter = require('./routes/profiles')
|
||||||
const app = express()
|
const app = express()
|
||||||
const corsOptions = {
|
|
||||||
origin: 'http://localhost:'.concat(config.get('Client.listeningPort')),
|
|
||||||
credentials: true
|
|
||||||
}
|
|
||||||
const fileStoreOptions = {
|
const fileStoreOptions = {
|
||||||
path: config.get('Server.sessionFileStorePath')
|
path: config.get('Server.sessionFileStorePath')
|
||||||
}
|
}
|
||||||
@@ -20,10 +16,12 @@ const fileStoreOptions = {
|
|||||||
require('./boot/db')()
|
require('./boot/db')()
|
||||||
require('./boot/auth')()
|
require('./boot/auth')()
|
||||||
|
|
||||||
app.use(cors(corsOptions))
|
|
||||||
app.use(express.json())
|
app.use(express.json())
|
||||||
app.use(express.urlencoded({ extended: false }))
|
app.use(express.urlencoded({ extended: false }))
|
||||||
app.use(cookieParser())
|
app.use(cookieParser())
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
app.use(express.static(path.join(__dirname, '../dist')))
|
||||||
|
}
|
||||||
app.use(session({
|
app.use(session({
|
||||||
store: new FileStore(fileStoreOptions),
|
store: new FileStore(fileStoreOptions),
|
||||||
secret: config.get('Server.sessionSecret'),
|
secret: config.get('Server.sessionSecret'),
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
const app = require('../app')
|
const app = require('../app')
|
||||||
const debug = require('debug')('example:server')
|
const debug = require('debug')('example:server')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
@@ -10,9 +7,6 @@ const config = require('config')
|
|||||||
const tls = config.get('Server.tls')
|
const tls = config.get('Server.tls')
|
||||||
const http = require(tls ? 'https' : 'http')
|
const http = require(tls ? 'https' : 'http')
|
||||||
|
|
||||||
/**
|
|
||||||
* Get port from environment and store in Express.
|
|
||||||
*/
|
|
||||||
const port = normalizePort(config.get('Server.listeningPort'))
|
const port = normalizePort(config.get('Server.listeningPort'))
|
||||||
app.set('port', port)
|
app.set('port', port)
|
||||||
|
|
||||||
@@ -26,16 +20,10 @@ if (tls) {
|
|||||||
server = http.createServer(httpsOptions, app)
|
server = http.createServer(httpsOptions, app)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Listen on provided port, on all network interfaces.
|
|
||||||
*/
|
|
||||||
server.listen(port)
|
server.listen(port)
|
||||||
server.on('error', onError)
|
server.on('error', onError)
|
||||||
server.on('listening', onListening)
|
server.on('listening', onListening)
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalize a port into a number, string, or false.
|
|
||||||
*/
|
|
||||||
function normalizePort (val) {
|
function normalizePort (val) {
|
||||||
const port = parseInt(val, 10)
|
const port = parseInt(val, 10)
|
||||||
|
|
||||||
@@ -52,9 +40,6 @@ function normalizePort (val) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Event listener for HTTP server "error" event.
|
|
||||||
*/
|
|
||||||
function onError (error) {
|
function onError (error) {
|
||||||
if (error.syscall !== 'listen') {
|
if (error.syscall !== 'listen') {
|
||||||
throw error
|
throw error
|
||||||
@@ -77,9 +62,6 @@ function onError (error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Event listener for HTTP server "listening" event.
|
|
||||||
*/
|
|
||||||
function onListening () {
|
function onListening () {
|
||||||
const addr = server.address()
|
const addr = server.address()
|
||||||
const bind = typeof addr === 'string'
|
const bind = typeof addr === 'string'
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ router.patch('/users/:userId', function (req, res) {
|
|||||||
return res.sendStatus(401)
|
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) {
|
if (err) {
|
||||||
return res.sendStatus(500)
|
return res.sendStatus(500)
|
||||||
}
|
}
|
||||||
|
|||||||
7
src/axios.js
Normal file
7
src/axios.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import Axios from 'axios'
|
||||||
|
|
||||||
|
const instance = Axios.create({
|
||||||
|
withCredentials: true
|
||||||
|
})
|
||||||
|
|
||||||
|
export default instance
|
||||||
@@ -82,7 +82,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getUsers () {
|
getUsers () {
|
||||||
this.$http.get('https://localhost:3000/users')
|
this.$http.get('/users')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
this.users = response.data.users
|
this.users = response.data.users
|
||||||
@@ -93,8 +93,8 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
updateUser (id, isAdmin) {
|
updateUser (id, isAdmin) {
|
||||||
this.$http.patch('https://localhost:3000/users/'.concat(id), {
|
this.$http.patch('/users/'.concat(id), {
|
||||||
isAdmin: isAdmin ? 1 : 0
|
isAdmin: isAdmin
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
@@ -107,7 +107,7 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
deleteUser (id) {
|
deleteUser (id) {
|
||||||
this.$http.delete('https://localhost:3000/users/'.concat(id))
|
this.$http.delete('/users/'.concat(id))
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
this.getUsers()
|
this.getUsers()
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export default {
|
|||||||
this.$router.push('/admin')
|
this.$router.push('/admin')
|
||||||
},
|
},
|
||||||
logout () {
|
logout () {
|
||||||
this.$http.get('https://localhost:3000/logout')
|
this.$http.get('/logout')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
this.$router.push('/login')
|
this.$router.push('/login')
|
||||||
@@ -92,7 +92,7 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
openDrawyer () {
|
openDrawyer () {
|
||||||
this.$http.get('https://localhost:3000/users/current')
|
this.$http.get('/users/current')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.data.user.isAdmin) {
|
if (response.data.user.isAdmin) {
|
||||||
this.isAdmin = true
|
this.isAdmin = true
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export default {
|
|||||||
}),
|
}),
|
||||||
methods: {
|
methods: {
|
||||||
login () {
|
login () {
|
||||||
this.$http.post('https://localhost:3000/login/password', {
|
this.$http.post('/login/password', {
|
||||||
username: this.username,
|
username: this.username,
|
||||||
password: this.password
|
password: this.password
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ export default {
|
|||||||
}),
|
}),
|
||||||
methods: {
|
methods: {
|
||||||
register () {
|
register () {
|
||||||
this.$http.post('https://localhost:3000/users', {
|
this.$http.post('/users', {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
username: this.username,
|
username: this.username,
|
||||||
password: this.password,
|
password: this.password,
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
populateProfileItems () {
|
populateProfileItems () {
|
||||||
this.$http.get('https://localhost:3000/profiles')
|
this.$http.get('/profiles')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
this.profileItems = response.data.profiles
|
this.profileItems = response.data.profiles
|
||||||
@@ -144,7 +144,7 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
saveProfile () {
|
saveProfile () {
|
||||||
this.$http.post('https://localhost:3000/profiles', {
|
this.$http.post('/profiles', {
|
||||||
name: this.profileName,
|
name: this.profileName,
|
||||||
isTimerEnabled: this.isTimerEnabled,
|
isTimerEnabled: this.isTimerEnabled,
|
||||||
duration: this.duration,
|
duration: this.duration,
|
||||||
@@ -169,7 +169,7 @@ export default {
|
|||||||
this.populateProfileItems()
|
this.populateProfileItems()
|
||||||
},
|
},
|
||||||
loadProfile () {
|
loadProfile () {
|
||||||
this.$http.get('https://localhost:3000/profiles/'.concat(this.selectedProfile.id))
|
this.$http.get('/profiles/'.concat(this.selectedProfile.id))
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const profile = response.data.profile
|
const profile = response.data.profile
|
||||||
@@ -195,7 +195,7 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
deleteProfile () {
|
deleteProfile () {
|
||||||
this.$http.delete('https://localhost:3000/profiles/'.concat(this.selectedProfile.id))
|
this.$http.delete('/profiles/'.concat(this.selectedProfile.id))
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
this.populateProfileItems()
|
this.populateProfileItems()
|
||||||
|
|||||||
@@ -2,12 +2,7 @@ import Vue from 'vue'
|
|||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
import vuetify from './plugins/vuetify'
|
import vuetify from './plugins/vuetify'
|
||||||
import Axios from 'axios'
|
import instance from './axios'
|
||||||
|
|
||||||
const instance = Axios.create({
|
|
||||||
baseURL: 'https://localhost:3000',
|
|
||||||
withCredentials: true
|
|
||||||
})
|
|
||||||
|
|
||||||
Vue.prototype.$http = instance
|
Vue.prototype.$http = instance
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Axios from 'axios'
|
|
||||||
import VueRouter from 'vue-router'
|
import VueRouter from 'vue-router'
|
||||||
import Home from '../views/Home.vue'
|
import Home from '../views/Home.vue'
|
||||||
|
import instance from '../axios'
|
||||||
const instance = Axios.create({
|
|
||||||
baseURL: 'https://localhost:3000',
|
|
||||||
withCredentials: true
|
|
||||||
})
|
|
||||||
|
|
||||||
Vue.use(VueRouter)
|
Vue.use(VueRouter)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
transpileDependencies: [
|
transpileDependencies: [
|
||||||
'vuetify'
|
'vuetify'
|
||||||
]
|
],
|
||||||
|
devServer: {
|
||||||
|
proxy: 'http://localhost:3000'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user