hanford / next-offline

make your Next.js application work offline using service workers via Google's workbox
https://github.com/hanford/next-offline
1.59k stars 111 forks source link

Cannot serve service-worker.js - express #230

Closed HelloMyDevWorld closed 4 years ago

HelloMyDevWorld commented 4 years ago

Hello,

I am very very sad that there is no example with custom server like express, and no tutorial how to step by step adjust it.

I was trying a bunch of configuration and i still have frontend_1 | /.next/service-worker.js frontend_1 | Error: ENOENT: no such file or directory, stat '/.next/service-worker.js'

router.get('/service-worker.js',async (req, res) => { var pathname = '/service-worker.js' const filePath = join(__dirname, '../../.next', pathname); app.serveStatic(req, res, filePath) })

const filePath = join(__dirname, '..', '..', pathname)
const filePath = join(__dirname, '..', '.next', pathname)
const filePath = join(__dirname, '../../.next', pathname);

const filePath = join(dirname, '../..', pathname); const filePath = join(dirname, '.next', '/service-worker.js')

What is wrong ? Do i have some missing configuration in nextjs to serve that files ?

HelloMyDevWorld commented 4 years ago

express:

router.get('/service-worker.js',async (req, res) => { app.serveStatic(req, res, './.next/service-worker.js') })