Skip to content

Commit

Permalink
refactor(app.vue): update API endpoint to '/json' for fetching IP
Browse files Browse the repository at this point in the history
docs(DEVELOPERS.md): clarify branch name for PR submissions
feat(nuxt.config.ts): add server middleware for '/raw' and '/json' routes
chore(package.json): add resolution for 'supports-color' dependency
refactor: replace ip.js with separate route handlers for '/json' and '/raw'

The API endpoint in `app.vue` is updated to '/json' to align with the new route structure. The documentation is updated to specify the correct branch name for PR submissions, improving clarity for developers. The `nuxt.config.ts` file now includes server middleware for '/raw' and '/json' routes, allowing for more flexible handling of IP requests. The `package.json` file includes a resolution for the 'supports-color' dependency to ensure compatibility. The `ip.js` file is removed and replaced with separate route handlers for '/json' and '/raw', improving code organization and maintainability.
  • Loading branch information
mauvehed committed Dec 7, 2024
1 parent 53a4513 commit 296b5a3
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 165 deletions.
2 changes: 1 addition & 1 deletion app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ip = ref(null);
onMounted(async () => {
try {
const res = await fetch("/api/ip");
const res = await fetch("/json");
const data = await res.json();
ip.value = data.ip;
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion docs/DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ git commit -m "Implement new feature"

### Developers

Submit a PR to merge your feature changes to the `develop` branch
Submit a PR to merge your feature changes to the `origin/develop` branch

### Maintainers

Expand Down
6 changes: 5 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2024-11-01',
devtools: { enabled: true }
devtools: { enabled: true },
serverMiddleware: [
{ path: '/raw', handler: '~/server/ip.js' },
{ path: '/json', handler: '~/server/ip.js' },
],
})
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"vue": "latest",
"vue-router": "latest"
},
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610",
"resolutions": {
"supports-color": "7.1.0"
}
}
7 changes: 0 additions & 7 deletions server/api/ip.js

This file was deleted.

7 changes: 7 additions & 0 deletions server/routes/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineEventHandler, getRequestHeaders } from 'h3';

export default defineEventHandler((event) => {
const headers = getRequestHeaders(event);
const userIp = headers['x-forwarded-for'] || event.node.req.socket.remoteAddress;
return { ip: userIp };
});
8 changes: 8 additions & 0 deletions server/routes/raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineEventHandler, getRequestHeaders } from 'h3';

export default defineEventHandler((event) => {
const headers = getRequestHeaders(event);
const userIp = headers['x-forwarded-for'] || event.node.req.socket.remoteAddress;
event.res.setHeader('Content-Type', 'text/plain');
return userIp;
});
311 changes: 157 additions & 154 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 296b5a3

Please sign in to comment.