8000 first commit · thecodingmachine/symfony-vuejs@2304b95 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2304b95

Browse files
author
Julien Neuhart
committed
first commit
0 parents  commit 2304b95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+14042
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 TheCodingMachine
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Source code of the tutorial [thecodingmachine.io/building-a-single-page-application-with-symfony-4-and-vuejs](https://thecodingmachine.io/building-a-single-page-application-with-symfony-4-and-vuejs).

app/.env.dist

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This file is a "template" of which env vars need to be defined for your application
2+
# Copy this file to .env file for development, create environment variables when deploying to production
3+
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
4+
5+
###> symfony/framework-bundle ###
6+
APP_ENV=dev
7+
APP_SECRET=8d2a5c935d8ef1c0e2b751147382bc75
8+
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
9+
#TRUSTED_HOSTS=localhost,example.com
10+
###< symfony/framework-bundle ###
11+
12+
###> doctrine/doctrine-bundle ###
13+
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
14+
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
15+
# Configure your db driver and server_version in config/packages/doctrine.yaml
16+
DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name
17+
###< doctrine/doctrine-bundle ###
18+
19+
###> symfony/swiftmailer-bundle ###
20+
# For Gmail as a transport, use: "gmail://username:password@localhost"
21+
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
22+
# Delivery is disabled by default via "null://localhost"
23+
MAILER_URL=null://localhost
24+
###< symfony/swiftmailer-bundle ###

app/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
###> symfony/framework-bundle ###
3+
/.env
4+
/public/bundles/
5+
/var/
6+
/vendor/
7+
###< symfony/framework-bundle ###
8+
9+
###> symfony/phpunit-bridge ###
10+
.phpunit
11+
/phpunit.xml
12+
###< symfony/phpunit-bridge ###
13+
14+
###> symfony/web-server-bundle ###
15+
/.web-server-pid
16+
###< symfony/web-server-bundle ###
17+
18+
###> symfony/webpack-encore-pack ###
19+
/node_modules/
20+
/public/build/
21+
npm-debug.log
22+
yarn-error.log
23+
###< symfony/webpack-encore-pack ###

app/assets/.gitignore

Whitespace-only changes.

app/assets/vue/App.vue

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template>
2+
<div class="container">
3+
<nav class="navbar navbar-expand-lg navbar-light bg-light">
4+
<router-link class="navbar-brand" to="/home">App</router-link>
5+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
6+
<span class="navbar-toggler-icon"></span>
7+
</button>
8+
<div class="collapse navbar-collapse" id="navbarNav">
9+
<ul class="navbar-nav">
10+
<router-link class="nav-item" tag="li" to="/home" active-class="active">
11+
<a class="nav-link">Home</a>
12+
</router-link>
13+
<router-link class="nav-item" tag="li" to="/posts" active-class="active">
14+
<a class="nav-link">Posts</a>
15+
</router-link>
16+
<li class="nav-item">
17+
<a class="nav-link" href="/api/security/logout">Logout</a>
18+
</li>
19+
</ul>
20+
</div>
21+
</nav>
22+
23+
<router-view></router-view>
24+
</div>
25+
</template>
26+
27+
<script>
28+
import axios from 'axios';
29+
import router from './router';
30+
31+
export default {
32+
name: 'app',
33+
created () {
34+
axios.interceptors.response.use(undefined, (err) => {
35+
return new Promise(() => {
36+
if (err.response.status === 403) {
37+
this.$router.push({path: '/login'})
38+
}
39+
throw err;
40+
});
41+
});
42+
},
43+
beforeMount () {
44+
let vueRouting = this.$parent.$el.attributes['data-vue-routing'].value,
45+
queryParameters = JSON.parse(this.$parent.$el.attributes['data-query-parameters'].value);
46+
47+
router.push({path: vueRouting, query: queryParameters});
48+
},
49+
}
50+
</script>

app/assets/vue/api/post.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import axios from 'axios';
2+
3+
export default {
4+
create (message) {
5+
return axios.post(
6+
'/api/post/create',
7+
{
8+
message: message,
9+
}
10+
);
11+
},
12+
getAll () {
13+
return axios.get('/api/posts');
14+
},
15+
}

app/assets/vue/api/security.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import axios from 'axios';
2+
3+
export default {
4+
login (login, password) {
5+
return axios.post(
6+
'/api/security/login',
7+
{
8+
username: login,
9+
password: password
10+
}
11+
);
12+
},
13+
isAuthenticated () {
14+
return axios.get('/api/security/is-authenticated');
15+
},
16+
}

app/assets/vue/components/Post.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div class="card w-100 mt-2">
3+
<div class="card-body">
4+
{{ message }}
5+
</div>
6+
</div>
7+
</template>
8+
9+
<script>
10+
export default {
11+
name: 'post',
12+
props: ['message'],
13+
}
14+
</script>

app/assets/vue/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Vue from 'vue';
2+
import App from './App';
3+
import router from './router';
4+
import store from './store';
5+
6+
new Vue({
7+
template: '<App/>',
8+
components: { App },
9+
router,
10+
store,
11+
}).$mount('#app');

0 commit comments

Comments
 (0)
0