mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
serve static dir
This commit is contained in:
parent
e2ab55ad23
commit
5a14a7249b
|
@ -19,8 +19,13 @@ export default class Server {
|
||||||
|
|
||||||
async start (port) {
|
async start (port) {
|
||||||
this.router.get('/_next/:path+', async (req, res, params) => {
|
this.router.get('/_next/:path+', async (req, res, params) => {
|
||||||
const path = (params.path || []).join('/')
|
const p = resolve(__dirname, '../client', (params.path || []).join('/'))
|
||||||
await this.serveStatic(req, res, path)
|
await this.serveStatic(req, res, p)
|
||||||
|
})
|
||||||
|
|
||||||
|
this.router.get('/static/:path+', async (req, res, params) => {
|
||||||
|
const p = resolve(this.dir, 'static', (params.path || []).join('/'))
|
||||||
|
await this.serveStatic(req, res, p)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.router.get('/:path+.json', async (req, res, params) => {
|
this.router.get('/:path+.json', async (req, res, params) => {
|
||||||
|
@ -96,9 +101,8 @@ export default class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
serveStatic (req, res, path) {
|
serveStatic (req, res, path) {
|
||||||
const p = resolve(__dirname, '../client', path)
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
send(req, p)
|
send(req, path)
|
||||||
.on('error', (err) => {
|
.on('error', (err) => {
|
||||||
if ('ENOENT' === err.code) {
|
if ('ENOENT' === err.code) {
|
||||||
this.render404(req, res).then(resolve, reject)
|
this.render404(req, res).then(resolve, reject)
|
||||||
|
|
Loading…
Reference in a new issue