Skip to content
Permalink
Browse files

add /api/ping

  • Loading branch information...
galvez committed Apr 28, 2019
1 parent 23c19c8 commit c2b55c829ef6cd07bc2a4896ac97db8c825c4783
Showing with 24 additions and 1 deletion.
  1. +6 −0 api.js
  2. +6 −1 nuxt.config.js
  3. +12 −0 pages/index.vue
6 api.js
@@ -1,2 +1,8 @@
export default [
{
path: '/api/ping',
handler(req, res, next) {
res.end(`API pong at ${new Date().getTime()}`)
}
}
]
@@ -3,5 +3,10 @@ import serverMiddleware from './api'
export default {
serverMiddleware,
modules: ['@nuxt/http'],
http: {}
server: {
port: 3030,
},
http: {
baseURL: 'http://localhost:3030'
}
}
@@ -14,5 +14,17 @@

<script>
export default {
data: () => ({
form: {}
}),
async asyncData({ app }) {
const response = await app.$http.get('api/ping')
return {
pongMessage: await response.text()
}
},
mounted() {
alert(this.pongMessage)
}
}
</script>

0 comments on commit c2b55c8

Please sign in to comment.
You can’t perform that action at this time.