Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
73
Frontend-Learner/node_modules/koa-static/index.js
generated
vendored
Normal file
73
Frontend-Learner/node_modules/koa-static/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const debug = require('debug')('koa-static')
|
||||
const { resolve } = require('path')
|
||||
const assert = require('assert')
|
||||
const send = require('koa-send')
|
||||
|
||||
/**
|
||||
* Expose `serve()`.
|
||||
*/
|
||||
|
||||
module.exports = serve
|
||||
|
||||
/**
|
||||
* Serve static files from `root`.
|
||||
*
|
||||
* @param {String} root
|
||||
* @param {Object} [opts]
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function serve (root, opts) {
|
||||
opts = Object.assign({}, opts)
|
||||
|
||||
assert(root, 'root directory is required to serve files')
|
||||
|
||||
// options
|
||||
debug('static "%s" %j', root, opts)
|
||||
opts.root = resolve(root)
|
||||
if (opts.index !== false) opts.index = opts.index || 'index.html'
|
||||
|
||||
if (!opts.defer) {
|
||||
return async function serve (ctx, next) {
|
||||
let done = false
|
||||
|
||||
if (ctx.method === 'HEAD' || ctx.method === 'GET') {
|
||||
try {
|
||||
done = await send(ctx, ctx.path, opts)
|
||||
} catch (err) {
|
||||
if (err.status !== 404) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!done) {
|
||||
await next()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return async function serve (ctx, next) {
|
||||
await next()
|
||||
|
||||
if (ctx.method !== 'HEAD' && ctx.method !== 'GET') return
|
||||
// response is already handled
|
||||
if (ctx.body != null || ctx.status !== 404) return // eslint-disable-line
|
||||
|
||||
try {
|
||||
await send(ctx, ctx.path, opts)
|
||||
} catch (err) {
|
||||
if (err.status !== 404) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue