mirror of
https://github.com/typicode/json-server.git
synced 2025-07-31 14:12:38 +08:00
webpack 4 + preact (#786)
This commit is contained in:
@ -10,7 +10,7 @@ const bodyParser = require('./body-parser')
|
||||
|
||||
module.exports = function(opts) {
|
||||
const userDir = path.join(process.cwd(), 'public')
|
||||
const defaultDir = path.join(__dirname, 'public')
|
||||
const defaultDir = path.join(__dirname, '../../dist')
|
||||
const staticDir = fs.existsSync(userDir) ? userDir : defaultDir
|
||||
|
||||
opts = objectAssign({ logger: true, static: staticDir }, opts)
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 318 B |
Binary file not shown.
Before Width: | Height: | Size: 278 B |
@ -1,61 +0,0 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>JSON Server</title>
|
||||
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
|
||||
<link rel="stylesheet" href="//cdn.rawgit.com/necolas/normalize.css/master/normalize.css">
|
||||
<link rel="stylesheet" href="//cdn.rawgit.com/milligram/milligram/master/dist/milligram.min.css">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<div class="container">
|
||||
<h3>JSON Server</h3>
|
||||
</div>
|
||||
</header>
|
||||
<main>
|
||||
<div class="container">
|
||||
<h4>Congrats!</h4>
|
||||
<p>
|
||||
You're successfully running JSON Server
|
||||
<br> ✧*。٩(ˊᗜˋ*)و✧*。
|
||||
</p>
|
||||
|
||||
<div id="resources"></div>
|
||||
|
||||
<p>
|
||||
To access and modify resources, you can use any HTTP method
|
||||
<br>
|
||||
<code>GET</code>
|
||||
<code>POST</code>
|
||||
<code>PUT</code>
|
||||
<code>PATCH</code>
|
||||
<code>DELETE</code>
|
||||
<code>OPTIONS</code>
|
||||
</p>
|
||||
|
||||
<div id="custom-routes"></div>
|
||||
|
||||
<h4>Documentation</h4>
|
||||
<p>
|
||||
View
|
||||
<a href="https://github.com/typicode/json-server">README</a>
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div class="container">
|
||||
<p>
|
||||
To replace this page, create a
|
||||
<code>./public/index.html</code> file.
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="https://unpkg.com/mithril/mithril.min.js"></script>
|
||||
<script src="main.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -1,57 +0,0 @@
|
||||
/* global m */
|
||||
|
||||
// Resource list
|
||||
var db = {}
|
||||
|
||||
m.request('db').then(function(data) {
|
||||
db = data
|
||||
})
|
||||
|
||||
m.mount(document.getElementById('resources'), {
|
||||
view: function() {
|
||||
var keys = Object.keys(db)
|
||||
var resourceList = m(
|
||||
'ul',
|
||||
keys
|
||||
.map(function(key) {
|
||||
return m('li', [
|
||||
m('a', { href: key }, '/' + key),
|
||||
m(
|
||||
'sup',
|
||||
Array.isArray(db[key]) ? ' ' + db[key].length + 'x' : ' object'
|
||||
)
|
||||
])
|
||||
})
|
||||
.concat([m('a', { href: 'db' }, '/db'), m('sup', m('em', ' state'))])
|
||||
)
|
||||
|
||||
return [
|
||||
m('h4', 'Resources'),
|
||||
keys.length ? resourceList : m('p', 'No resources found')
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
// Custom routes
|
||||
var customRoutes = {}
|
||||
|
||||
m.request('__rules').then(function(data) {
|
||||
customRoutes = data
|
||||
})
|
||||
|
||||
m.mount(document.getElementById('custom-routes'), {
|
||||
view: function() {
|
||||
var rules = Object.keys(customRoutes)
|
||||
if (rules.length) {
|
||||
return [
|
||||
m('h4', 'Custom routes'),
|
||||
m(
|
||||
'table',
|
||||
rules.map(function(rule) {
|
||||
return m('tr', [m('td', rule), m('td', '⇢ ' + customRoutes[rule])])
|
||||
})
|
||||
)
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
@ -1,73 +0,0 @@
|
||||
html {
|
||||
font-size: 70%;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
flex-direction: column;
|
||||
padding:0;
|
||||
margin: 0;
|
||||
color: #333;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
header {
|
||||
padding-top: 2.0rem;
|
||||
border-bottom: 1px solid #EEE;
|
||||
}
|
||||
|
||||
header a, header a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
main {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
footer {
|
||||
padding-top: 2.5rem;
|
||||
border-top: 1px solid #EEE;
|
||||
}
|
||||
|
||||
h4 {
|
||||
margin-top: 4rem;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #0275d8;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #014c8c;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
table {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
td {
|
||||
border: 0;
|
||||
padding: 0 1em .5em 0;
|
||||
color: #014c8c;
|
||||
}
|
||||
|
||||
td:first-child {
|
||||
width: 1%;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style-position: inside;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
li {
|
||||
list-style-type: none;
|
||||
margin-bottom: .2rem;
|
||||
}
|
||||
|
||||
code {
|
||||
border-radius: 0;
|
||||
}
|
Reference in New Issue
Block a user