-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal-server.js
More file actions
41 lines (37 loc) · 1.09 KB
/
local-server.js
File metadata and controls
41 lines (37 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict'
const path = require('path')
const { Backend, RestApi, ServingFilesEndpoint, NotFoundEndpoint } = require('@cuties/rest')
const CustomIndexEndpoint = require('./endpoints/CustomIndexEndpoint')
const mapperForStatic = (url) => {
const parts = url.split('?')[0].split('/').filter(part => part !== '')
return path.join(...parts)
}
const mapperForSrc = (url) => {
const mainPart = `${url.split('.html')[0]}.html`
const parts = mainPart.split('/').filter(part => part !== '')
return path.join(...parts)
}
new Backend(
'http',
4200,
'127.0.0.1',
new RestApi(
new CustomIndexEndpoint(
'./html/index.html',
new NotFoundEndpoint(new RegExp(/\/not-found/))
),
new ServingFilesEndpoint(
new RegExp(/^\/(html|js|json|image|css|md|font)/),
mapperForStatic,
{},
new NotFoundEndpoint(new RegExp(/\/not-found/))
),
new ServingFilesEndpoint(
new RegExp(/[^\s]+.html([/?][^\s]*)?$/),
mapperForSrc,
{},
new NotFoundEndpoint(new RegExp(/\/not-found/))
),
new NotFoundEndpoint(new RegExp(/\/not-found/))
)
).call()