poops 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/poops.js +16 -5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "poops",
3
3
  "description": "Straightforward, no-bullshit bundler for the web.",
4
- "version": "1.2.0",
4
+ "version": "1.2.1",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "poops.js",
package/poops.js CHANGED
@@ -206,11 +206,22 @@ async function startServer() {
206
206
  await poops() // Initial compilation before starting the server
207
207
  const app = connect()
208
208
 
209
- if (config.serve.base && pathExists(cwd, config.serve.base)) {
210
- app.use(serveStatic(path.join(cwd, config.serve.base)))
211
- } else {
212
- app.use(serveStatic(cwd))
213
- }
209
+ const base = config.serve.base && pathExists(cwd, config.serve.base)
210
+ ? path.join(cwd, config.serve.base)
211
+ : cwd
212
+
213
+ app.use(serveStatic(base))
214
+
215
+ // Serve 404.html for unmatched routes
216
+ const notFoundPage = path.join(base, '404.html')
217
+ app.use((req, res) => {
218
+ res.statusCode = 404
219
+ if (pathExists(notFoundPage)) {
220
+ fs.createReadStream(notFoundPage).pipe(res)
221
+ } else {
222
+ res.end('Not Found')
223
+ }
224
+ })
214
225
 
215
226
  let port = overridePort || config.serve.port || 4040
216
227
  if (!overridePort) port = await getAvailablePort(port, port + 10)