I’ve hosted my vue.js SPA on netlify and I want to make it SEO compatible. One solution was to enable netlify’s built-in pre-rendering but debugging on it is a nightmare (due to 24-48 hrs non-clearable cache). So I’m trying to integrate preredner.io service together with netlify’s functions.
For this reason I’ve created a funciton in netlify/functions/server.js
with following content…
'use strict'
const express = require('express')
const path = require('path')
const serverless = require('serverless-http')
const app = express()
const prerender = require('prerender-node')
const router = express.Router()
router.get('/', (req, res) => {
res.writeHead(200, { 'Content-Type': 'text/html' })
res.write('<h1>Hello from Express.js!</h1>')
res.end()
})
router.get('/another', (req, res) => res.json({ route: req.originalUrl }))
router.post('/', (req, res) => res.json({ postBody: req.body }))
app.use(prerender.set('prerenderToken', 'MY_TOKEN'))
app.use(express.json())
app.use('/.netlify/functions/server', router) // path must route to lambda
app.use('/', (req, res) => res.sendFile(path.join(__dirname, '../index.html')))
module.exports = app
module.exports.handler = serverless(app)
I’ve deployed this function to my site, but the issue is I’m not getting any pre-renderd page when visiting the site by setting UserAgent as GoogleBot
. I’ve not made any other change to my codebase. Am I missing something?