-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
301 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
This is a base project to get started using Vue with Spring Boot Web. | ||
|
||
This project is designed to package the compiled code into a `.war` for deployment into web containers (default: Tomcat). | ||
|
||
# Node npm & Vue CLI | ||
You will need npm and the Vue CLI intalled. [Full Instructions](https://cli.vuejs.org/guide/installation.html) | ||
## npm | ||
Goto the [Node.js Site](https://nodejs.org/en/) to install. | ||
## Vue CLI | ||
``` | ||
npm install -g @vue/cli | ||
``` | ||
|
||
# Building and running | ||
Here are some commands to get build and run the application | ||
## Development | ||
These sets of commands will continously build & serve the client and server as files change. | ||
You will need 2 terminals open because the watch commands are interactive | ||
|
||
### Terminal 1 - Building the client app | ||
``` | ||
cd client | ||
npm run build-dev | ||
``` | ||
### Terminal 2 - Building and serving server w/SPA hosting | ||
``` | ||
cd server | ||
mvn spring-boot:run -Dspring-boot.run.profiles=development | ||
``` | ||
### Alternative | ||
These can be executed with the Vue UI and your IDE if desired; | ||
just adjust the run configuration to match. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
presets: ["@vue/app"] | ||
presets: ['@vue/app'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import Vue from "vue"; | ||
import App from "./App.vue"; | ||
import router from "./router"; | ||
import Vue from 'vue'; | ||
import App from '@/App.vue'; | ||
import router from '@/router'; | ||
|
||
Vue.config.productionTip = false; | ||
|
||
new Vue({ | ||
router, | ||
render: h => h(App) | ||
}).$mount("#app"); | ||
}).$mount('#app'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
import Vue from "vue"; | ||
import Router from "vue-router"; | ||
import Home from "./views/Home.vue"; | ||
import Vue from 'vue'; | ||
import Router from 'vue-router'; | ||
import Home from '@/views/Home.vue'; | ||
import Counter from '@/views/Counter.vue'; | ||
|
||
Vue.use(Router); | ||
|
||
export default new Router({ | ||
mode: "history", | ||
mode: 'history', | ||
base: process.env.BASE_URL, | ||
routes: [ | ||
{ | ||
path: "/", | ||
name: "home", | ||
path: '/', | ||
name: 'home', | ||
component: Home | ||
}, | ||
{ | ||
path: "/about", | ||
name: "about", | ||
path: '/about', | ||
name: 'about', | ||
// route level code-splitting | ||
// this generates a separate chunk (about.[hash].js) for this route | ||
// which is lazy-loaded when the route is visited. | ||
component: () => | ||
import(/* webpackChunkName: "about" */ "./views/About.vue") | ||
import(/* webpackChunkName: "about" */ '@/views/About.vue') | ||
}, | ||
{ | ||
path: '/counter', | ||
name: 'counter', | ||
component: Counter | ||
} | ||
] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import ServerAPI from '@/services/ServerAPI.js'; | ||
|
||
export default { | ||
getVisitCount() { | ||
return ServerAPI.getConnection().get('/counter'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import axios from 'axios'; | ||
|
||
const apiClient = axios.create({ | ||
baseURL: '/api', | ||
withCredentials: false, | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
|
||
export default { | ||
getConnection() { | ||
return apiClient; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<template> | ||
<div> | ||
<h1>Visit Counter</h1> | ||
<p> | ||
The site has been visited | ||
{{ visitCount ? visitCount : '[Calculating...]' }} times. | ||
</p> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import CounterService from '@/services/CounterService.js'; | ||
export default { | ||
data() { | ||
return { | ||
visitCount: null | ||
}; | ||
}, | ||
created() { | ||
console.log('Starting Call'); | ||
CounterService.getVisitCount() | ||
.then(response => { | ||
this.visitCount = response.data; | ||
}) | ||
.catch(error => { | ||
this.visitCount = 'error'; | ||
console.log('There was an error:', error.response); | ||
}); | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
outputDir: '../server/src/main/resources/spa' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
server/src/main/java/geozak/springvue/server/controller/CounterController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package geozak.springvue.server.controller; | ||
|
||
import geozak.springvue.server.service.CounterService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
public class CounterController { | ||
|
||
@Autowired private CounterService counterService; | ||
|
||
@GetMapping("/counter") | ||
public Integer getVisitCount() { | ||
|
||
return counterService.incrementVisitCount(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
server/src/main/java/geozak/springvue/server/service/CounterService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package geozak.springvue.server.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class CounterService { | ||
|
||
private int visitCount = 0; | ||
|
||
public int incrementVisitCount() { | ||
return ++visitCount; | ||
} | ||
} |
Oops, something went wrong.