mirror of
https://github.com/typicode/json-server.git
synced 2025-08-01 09:13:32 +08:00
Refactor
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
const url = require('url')
|
||||
const express = require('express')
|
||||
const _ = require('lodash')
|
||||
const pluralize = require('pluralize')
|
||||
const write = require('./write')
|
||||
const getFullURL = require('./get-full-url')
|
||||
const utils = require('../utils')
|
||||
|
||||
module.exports = (db, name) => {
|
||||
@ -34,15 +34,6 @@ module.exports = (db, name) => {
|
||||
})
|
||||
}
|
||||
|
||||
function getFullURL (req) {
|
||||
const root = url.format({
|
||||
protocol: req.protocol,
|
||||
host: req.get('host')
|
||||
})
|
||||
|
||||
return `${root}${req.originalUrl}`
|
||||
}
|
||||
|
||||
// GET /name
|
||||
// GET /name?q=
|
||||
// GET /name?attr=&attr=
|
||||
@ -250,7 +241,8 @@ module.exports = (db, name) => {
|
||||
.value()
|
||||
|
||||
res.setHeader('Access-Control-Expose-Headers', 'Location')
|
||||
res.setHeader('Location', getFullURL(req) + '/' + resource.id)
|
||||
res.location(`${getFullURL(req)}/${resource.id}`)
|
||||
|
||||
res.status(201)
|
||||
res.locals.data = resource
|
||||
|
||||
|
Reference in New Issue
Block a user