Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update nginx config, fit with v3 api #427

Merged
merged 1 commit into from
Aug 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions public/conf.d/docker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions public/conf.d/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion public/usr/config.example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"api": {
"backend": "/_api/backend/",
"backend": "/api/v3/",
"admin": ""
},
"footer": [
Expand Down
14 changes: 11 additions & 3 deletions src/assets/js/api.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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)) === '/' ? '/' : '');
}
}
6 changes: 0 additions & 6 deletions src/assets/js/router.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/PasswordAuth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/views/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default {
...mapGetters([
"view",
"lang",
"content"
"content",
"config"
])
},
watch: {
Expand All @@ -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);
Expand Down
86 changes: 0 additions & 86 deletions src/views/v2/Index.vue

This file was deleted.

5 changes: 2 additions & 3 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down