bez połacznia vue z backendem

This commit is contained in:
monastyr 2018-11-18 23:42:18 +01:00
parent 01b6a6e1c8
commit ae37039556
13 changed files with 167 additions and 12 deletions

View File

@ -5,6 +5,15 @@ package main
// go get github.com/golang/protobuf
//[!] błąd [!] can't load package: package github.com/golang/protobuf: no Go files in C:\Users\dp\go\src\github.com\golang\protobuf
//go get github.com/golang/protobuf/proto
//https://github.com/golang/protobuf
//go get -u github.com/golang/protobuf/protoc-gen-go dziala
//The compiler plugin, protoc-gen-go, will be installed in $GOBIN,
//defaulting to $GOPATH/bin. It must be in your $PATH for the protocol compiler, protoc, to find it.
//protoc
// 'protoc' is not recognized as an internal or external command,
// operable program or batch file.
import "fmt"
func main() {

View File

@ -1,4 +1,4 @@
{
"name": "elliot",
"name": "Elliot",
"age": 24
}

View File

@ -0,0 +1,8 @@
syntax="proto3"
package main;
message Person {
string name =1;
int32 age = 2;
}

View File

@ -0,0 +1,81 @@
package main
// go get -u github.com/gin-gonic/gin
// go get -u github.com/gin-gonic/contrib/static
// go get "github.com/gin-gonic/contrib/static"
// go get "github.com/gin-gonic/gin"
import (
"net/http"
"strconv"
"github.com/gin-gonic/contrib/static"
"github.com/gin-gonic/gin"
)
// Let's create our Jokes struct. This will contain information about a Joke
// Joke contains information about a single Joke
type Joke struct {
ID int `json:"id" binding:"required"`
Likes int `json:"likes"`
Joke string `json:"joke" binding:"required"`
}
// We'll create a list of jokes
var jokes = []Joke{
Joke{0, 0, "How does a penguin build it's house? Igloos it together."},
Joke{1, 0, "Did you hear about the restaurant on the moon? Great food, no atmosphere."},
Joke{2, 0, "What do you call a fake noodle? An Impasta."},
Joke{3, 0, "How many apples grow on a tree? All of them."},
Joke{4, 0, "Want to hear a joke about paper? Nevermind it's tearable."},
Joke{5, 0, "I just watched a program about beavers. It was the best dam program I've ever seen."},
Joke{6, 0, "Why did the coffee file a police report? It got mugged."},
}
func main() {
// Set the router as the default one shipped with Gin
router := gin.Default()
// Serve frontend static files
router.Use(static.Serve("/", static.LocalFile("./views", true)))
// Setup route group for the API
api := router.Group("/api")
{
api.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
}
// Our API will consit of just two routes
// /jokes - which will retrieve a list of jokes a user can see
// /jokes/like/:jokeID - which will capture likes sent to a particular joke
api.GET("/jokes", JokeHandler)
api.POST("/jokes/like/:jokeID", LikeJoke)
// Start and run the server
router.Run(":3000")
}
// JokeHandler retrieves a list of available jokes
func JokeHandler(c *gin.Context) {
c.Header("Content-Type", "application/json")
c.JSON(http.StatusOK, jokes)
}
// LikeJoke increments the likes of a particular joke Item
func LikeJoke(c *gin.Context) {
// confirm Joke ID sent is valid
// remember to import the `strconv` package
//jokeid - wartosc z url'a
if jokeid, err := strconv.Atoi(c.Param("jokeID")); err == nil {
// return a pointer to the updated jokes list
c.JSON(http.StatusOK, &jokes[jokeid])
} else {
// Joke ID is invalid
c.AbortWithStatus(http.StatusNotFound)
}
}

View File

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Jokeish App</title>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://cdn.auth0.com/js/auth0/9.0/auth0.min.js"></script>
<script type="application/javascript" src="https://unpkg.com/react@16.0.0/umd/react.production.min.js"></script>
<script type="application/javascript" src="https://unpkg.com/react-dom@16.0.0/umd/react-dom.production.min.js"></script>
<script type="application/javascript" src="https://unpkg.com/babel-standalone@6.26.0/babel.js"></script>
<script type="text/babel" src="js/app.jsx"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div id="app"></div>
</body>
</html>

0
couchdb_cheat_sheet.txt Normal file
View File

View File

@ -6,15 +6,28 @@ const path = require('path')
module.exports = {
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
proxyTable: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true
},
},
devServer: {
proxy: {
"/api/*": {
target: "http://localhost:3000",
secure: false,
pathRewrite: { '^/api': '' }
}
}
},
// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
port: 3000, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,

View File

@ -876,6 +876,15 @@
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==",
"dev": true
},
"axios": {
"version": "0.18.0",
"resolved": "http://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"requires": {
"follow-redirects": "^1.3.0",
"is-buffer": "^1.1.5"
}
},
"babel-code-frame": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
@ -5078,7 +5087,6 @@
"version": "1.5.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.9.tgz",
"integrity": "sha512-Bh65EZI/RU8nx0wbYF9shkFZlqLP+6WT/5FnA3cE/djNSuKNHJEinGGZgu/cQEkeeb2GdFOgenAmn8qaqYke2w==",
"dev": true,
"requires": {
"debug": "=3.1.0"
},
@ -5087,7 +5095,6 @@
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
@ -6591,8 +6598,7 @@
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
"dev": true
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
},
"is-builtin-module": {
"version": "1.0.0",
@ -8399,8 +8405,7 @@
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"multicast-dns": {
"version": "6.2.3",

View File

@ -14,6 +14,7 @@
"build": "node build/build.js"
},
"dependencies": {
"axios": "^0.18.0",
"bootstrap-vue": "^2.0.0-rc.11",
"vue": "^2.5.2",
"vue-router": "^3.0.1",

View File

@ -5,9 +5,27 @@
</template>
<script>
import axios from 'axios'
export default {
name: 'App'
name: 'App',
data(){
return {
}
},
methods: {
downloadData: function () {
console.log('Cokolwiek')
var formData = new FormData()
axios.post('/api/api/jokes/like/0', formData).then(response => {
console.log("Server response: ",response.data)
})
}
},
created: function () {
this.downloadData()
}
}
// https://codepen.io/anon/pen/BGzVpK
</script>

View File

@ -26,7 +26,6 @@
<script>
export default {
el: '#app',
methods: {
setActiveItemId(itemIndex) {
if (itemIndex === this.activeItemId) {

0
todo.txt Normal file
View File