diff --git a/public/conf.d/docker.conf b/public/conf.d/docker.conf
index 251bed32..0b9a3d12 100644
--- a/public/conf.d/docker.conf
+++ b/public/conf.d/docker.conf
@@ -8,18 +8,17 @@ server
gzip_http_version 1.0;
location / {
- try_files $uri $uri/ /index.html;
location ~ .*\.(js|css)?$ {
gzip_static on;
}
}
- location /_api/backend/ {
+ location /api/v3/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_pass http://pasteme-backend:8000/;
+ proxy_pass http://pasteme-backend:8000/api/v3/;
}
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
diff --git a/public/conf.d/nginx.conf b/public/conf.d/nginx.conf
index 8354da34..e2bbcbc7 100644
--- a/public/conf.d/nginx.conf
+++ b/public/conf.d/nginx.conf
@@ -3,21 +3,20 @@ server
listen 80;
server_name _;
index index.html;
- root /usr/local/pasteme;
+ root /www/pasteme;
location / {
- try_files $uri $uri/ /index.html;
location ~ .*\.(js|css)?$ {
gzip_static on;
}
}
- location /_api/backend/ {
+ location /api/v3/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_pass http://localhost:8000/;
+ proxy_pass http://localhost:8000/api/v3/;
}
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
diff --git a/public/usr/config.example.json b/public/usr/config.example.json
index 22bd4858..10baff31 100644
--- a/public/usr/config.example.json
+++ b/public/usr/config.example.json
@@ -1,6 +1,6 @@
{
"api": {
- "backend": "/_api/backend/",
+ "backend": "/api/v3/",
"admin": ""
},
"footer": [
diff --git a/src/assets/js/api.js b/src/assets/js/api.js
index f4e3227c..b1e05a9c 100644
--- a/src/assets/js/api.js
+++ b/src/assets/js/api.js
@@ -1,7 +1,11 @@
import axios from 'axios'
+function getLast(value) {
+ return value[value.length - 1];
+}
+
export default {
- get: function(url, params = {}, alert_error = true) {
+ get: function (url, params = {}, alert_error = true) {
return new Promise((resolve, reject) => {
axios.get(url, {
params: params,
@@ -18,7 +22,7 @@ export default {
});
});
},
- post: function(url, params = {}) {
+ post: function (url, params = {}) {
return new Promise((resolve, reject) => {
axios.post(url, params).then(response => {
resolve(response.data);
@@ -28,7 +32,7 @@ export default {
});
});
},
- put: function(url, params = {}) {
+ put: function (url, params = {}) {
return new Promise((resolve, reject) => {
axios.put(url, params).then(response => {
resolve(response.data);
@@ -37,5 +41,9 @@ export default {
reject(error);
});
});
+ },
+ join: function (...args) {
+ let result = args.map(pathPart => pathPart.replace(/(^\/|\/$)/g, "")).join("/");
+ return result + (getLast(getLast(args)) === '/' ? '/' : '');
}
}
diff --git a/src/assets/js/router.js b/src/assets/js/router.js
index 79247933..dcdad2eb 100644
--- a/src/assets/js/router.js
+++ b/src/assets/js/router.js
@@ -1,6 +1,5 @@
import Vue from "vue"
import Router from "vue-router"
-import v2Index from "../../views/v2/Index";
import View from "../../views/View";
import Home from "../../views/Home";
// eslint-disable-next-line no-unused-vars
@@ -30,11 +29,6 @@ export default new Router({
name: "view",
component: View
},
- {
- path: "/v2/:key(0{0}|[a-zA-Z0-9]{3,8})",
- name: "v2index",
- component: v2Index
- },
{
path: "/What_are_you_nong_sha_lei?",
name: "NotFound",
diff --git a/src/components/Form.vue b/src/components/Form.vue
index e35b2f12..962c637f 100644
--- a/src/components/Form.vue
+++ b/src/components/Form.vue
@@ -75,7 +75,7 @@ export default {
methods: {
onSubmit() {
this.api.post(
- `${this.$store.getters.config.api.backend}v3/paste/`,
+ this.api.join(this.$store.getters.config.api.backend, 'paste'),
this.form
).then(response => {
if (response.status === 201) {
diff --git a/src/components/PasswordAuth.vue b/src/components/PasswordAuth.vue
index f163b32c..a8bab8b2 100644
--- a/src/components/PasswordAuth.vue
+++ b/src/components/PasswordAuth.vue
@@ -32,7 +32,7 @@
},
methods: {
onSubmit() {
- const sendUrl = `${this.$store.getters.config.api.backend}v3/paste/${this.$route.params.key}`;
+ const sendUrl = this.api.join(this.$store.getters.config.api.backend, 'paste', this.$route.params.key);
this.api.get(sendUrl, this.form).then(({status, content, lang}) => {
if (status === 200) {
this.updateContent(content);
diff --git a/src/views/View.vue b/src/views/View.vue
index abf465c2..142c6926 100644
--- a/src/views/View.vue
+++ b/src/views/View.vue
@@ -22,7 +22,8 @@ export default {
...mapGetters([
"view",
"lang",
- "content"
+ "content",
+ "config"
])
},
watch: {
@@ -38,9 +39,8 @@ export default {
this.$store.commit("init");
this.updateView("loading");
- this.api.get(
- `${this.$store.getters.config.api.backend}v3/paste/${this.$route.params.key}`
- ).then(response => {
+ let url = this.api.join(this.config.api.backend, 'paste', this.$route.params.key)
+ this.api.get(url).then(response => {
if (response.status === 200) {
this.updateView("paste_view");
this.updateContent(response.content);
diff --git a/src/views/v2/Index.vue b/src/views/v2/Index.vue
deleted file mode 100644
index 68db7112..00000000
--- a/src/views/v2/Index.vue
+++ /dev/null
@@ -1,86 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/vue.config.js b/vue.config.js
index 9abcf7ba..8c8aa989 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -48,10 +48,9 @@ const cdn = {
module.exports = {
devServer: {
proxy: {
- "/api/": {
+ "/api/v3/": {
secure: false,
- // target: "http://dev.pasteme.lucien.ink/_api",
- target: "http://localhost:8000",
+ target: "http://localhost:8000/api/v3/",
changeOrigin: true
}
}