Skip to content

Commit 598081f

Browse files
Add express node server example
1 parent d4a7bc6 commit 598081f

File tree

4 files changed

+135
-25
lines changed

4 files changed

+135
-25
lines changed

loader.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ const extractPackageNameAndVersion =
1616
const importmap = new ImportMap({
1717
rootUrl: import.meta.url,
1818
map: existsSync(nodeImportMapPath)
19-
? JSON.parse(
20-
readFileSync(join(root, "node.importmap"), { encoding: "utf8" })
21-
)
19+
? JSON.parse(readFileSync(nodeImportMapPath, { encoding: "utf8" }))
2220
: {},
2321
});
2422

node.importmap

Lines changed: 105 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
"@teleporthq/teleport-project-generator-react": "https://ga.jspm.io/npm:@teleporthq/teleport-project-generator-react@0.25.4/dist/cjs/index.js",
44
"@teleporthq/teleport-types": "https://ga.jspm.io/npm:@teleporthq/teleport-types@0.25.2/dist/cjs/index.js",
55
"chalk": "https://ga.jspm.io/npm:chalk@5.2.0/source/index.js",
6-
"react": "https://ga.jspm.io/npm:react@17.0.2/dev.index.js",
7-
"react-dom": "https://ga.jspm.io/npm:react-dom@17.0.2/dev.index.js",
8-
"react-router": "https://ga.jspm.io/npm:react-router@5.2.1/dev.index.js",
9-
"react-router-dom": "https://ga.jspm.io/npm:react-router-dom@5.2.1/dev.index.js"
6+
"express": "https://ga.jspm.io/npm:express@4.18.2/index.js",
7+
"morgan": "https://ga.jspm.io/npm:morgan@1.10.0/index.js",
8+
"react": "https://ga.jspm.io/npm:react@17.0.2/index.js",
9+
"react-dom": "https://ga.jspm.io/npm:react-dom@17.0.2/index.js",
10+
"react-router": "https://ga.jspm.io/npm:react-router@5.2.1/index.js",
11+
"react-router-dom": "https://ga.jspm.io/npm:react-router-dom@5.2.1/index.js"
1012
},
1113
"scopes": {
1214
"https://ga.jspm.io/": {
1315
"#ansi-styles": "https://ga.jspm.io/npm:chalk@5.2.0/source/vendor/ansi-styles/index.js",
1416
"#supports-color": "https://ga.jspm.io/npm:chalk@5.2.0/source/vendor/supports-color/index.js",
17+
"#util.inspect.js": "https://ga.jspm.io/npm:object-inspect@1.12.3/util.inspect.js",
1518
"@babel/generator": "https://ga.jspm.io/npm:@babel/generator@7.21.1/lib/index.js",
1619
"@babel/helper-string-parser": "https://ga.jspm.io/npm:@babel/helper-string-parser@7.19.4/lib/index.js",
1720
"@babel/helper-validator-identifier": "https://ga.jspm.io/npm:@babel/helper-validator-identifier@7.19.1/lib/index.js",
@@ -51,68 +54,148 @@
5154
"@teleporthq/teleport-uidl-builders": "https://ga.jspm.io/npm:@teleporthq/teleport-uidl-builders@0.25.2/dist/cjs/index.js",
5255
"@teleporthq/teleport-uidl-resolver": "https://ga.jspm.io/npm:@teleporthq/teleport-uidl-resolver@0.25.4/dist/cjs/index.js",
5356
"@teleporthq/teleport-uidl-validator": "https://ga.jspm.io/npm:@teleporthq/teleport-uidl-validator@0.25.4/dist/cjs/index.js",
57+
"accepts": "https://ga.jspm.io/npm:accepts@1.3.8/index.js",
58+
"array-flatten": "https://ga.jspm.io/npm:array-flatten@1.1.1/array-flatten.js",
59+
"async_hooks": "node:async_hooks",
60+
"basic-auth": "https://ga.jspm.io/npm:basic-auth@2.0.1/index.js",
61+
"body-parser": "https://ga.jspm.io/npm:body-parser@1.20.1/index.js",
5462
"buffer": "node:buffer",
63+
"bytes": "https://ga.jspm.io/npm:bytes@3.1.2/index.js",
64+
"call-bind/callBound": "https://ga.jspm.io/npm:call-bind@1.0.2/callBound.js",
5565
"character-entities-html4": "https://ga.jspm.io/npm:character-entities-html4@1.1.4/index.json.js",
5666
"character-entities-legacy": "https://ga.jspm.io/npm:character-entities-legacy@1.1.4/index.json.js",
5767
"comma-separated-tokens": "https://ga.jspm.io/npm:comma-separated-tokens@1.0.8/index.js",
68+
"content-disposition": "https://ga.jspm.io/npm:content-disposition@0.5.4/index.js",
69+
"content-type": "https://ga.jspm.io/npm:content-type@1.0.5/index.js",
70+
"cookie": "https://ga.jspm.io/npm:cookie@0.5.0/index.js",
71+
"cookie-signature": "https://ga.jspm.io/npm:cookie-signature@1.0.6/index.js",
72+
"crypto": "node:crypto",
5873
"css-vendor": "https://ga.jspm.io/npm:css-vendor@2.0.8/dist/css-vendor.cjs.js",
74+
"debug": "https://ga.jspm.io/npm:debug@2.6.9/src/index.js",
5975
"deepmerge": "https://ga.jspm.io/npm:deepmerge@4.3.0/dist/cjs.js",
76+
"depd": "https://ga.jspm.io/npm:depd@2.0.0/index.js",
77+
"destroy": "https://ga.jspm.io/npm:destroy@1.2.0/index.js",
78+
"ee-first": "https://ga.jspm.io/npm:ee-first@1.1.1/index.js",
79+
"encodeurl": "https://ga.jspm.io/npm:encodeurl@1.0.2/index.js",
80+
"escape-html": "https://ga.jspm.io/npm:escape-html@1.0.3/index.js",
81+
"etag": "https://ga.jspm.io/npm:etag@1.8.1/index.js",
82+
"events": "node:events",
83+
"finalhandler": "https://ga.jspm.io/npm:finalhandler@1.2.0/index.js",
84+
"forwarded": "https://ga.jspm.io/npm:forwarded@0.2.0/index.js",
85+
"fresh": "https://ga.jspm.io/npm:fresh@0.5.2/index.js",
86+
"fs": "node:fs",
87+
"function-bind": "https://ga.jspm.io/npm:function-bind@1.1.1/index.js",
88+
"get-intrinsic": "https://ga.jspm.io/npm:get-intrinsic@1.2.0/index.js",
89+
"has": "https://ga.jspm.io/npm:has@1.0.3/src/index.js",
90+
"has-symbols": "https://ga.jspm.io/npm:has-symbols@1.0.3/index.js",
6091
"hast-util-is-element": "https://ga.jspm.io/npm:hast-util-is-element@1.1.0/index.js",
6192
"hast-util-whitespace": "https://ga.jspm.io/npm:hast-util-whitespace@1.0.4/index.js",
62-
"history": "https://ga.jspm.io/npm:history@4.10.1/dev.index.js",
93+
"history": "https://ga.jspm.io/npm:history@4.10.1/index.js",
6394
"hoist-non-react-statics": "https://ga.jspm.io/npm:hoist-non-react-statics@3.3.2/dist/hoist-non-react-statics.cjs.js",
6495
"html-void-elements": "https://ga.jspm.io/npm:html-void-elements@1.0.5/index.json.js",
6596
"html-whitespace-sensitive-tag-names": "https://ga.jspm.io/npm:html-whitespace-sensitive-tag-names@1.0.3/index.json.js",
97+
"http": "node:http",
98+
"http-errors": "https://ga.jspm.io/npm:http-errors@2.0.0/index.js",
6699
"hyphenate-style-name": "https://ga.jspm.io/npm:hyphenate-style-name@1.0.4/index.cjs.js",
100+
"iconv-lite": "https://ga.jspm.io/npm:iconv-lite@0.4.24/lib/index.js",
101+
"inherits": "https://ga.jspm.io/npm:inherits@2.0.4/inherits.js",
102+
"ipaddr.js": "https://ga.jspm.io/npm:ipaddr.js@1.9.1/lib/ipaddr.js",
67103
"is-alphabetical": "https://ga.jspm.io/npm:is-alphabetical@1.0.4/index.js",
68104
"is-alphanumerical": "https://ga.jspm.io/npm:is-alphanumerical@1.0.4/index.js",
69105
"is-decimal": "https://ga.jspm.io/npm:is-decimal@1.0.4/index.js",
70106
"is-hexadecimal": "https://ga.jspm.io/npm:is-hexadecimal@1.0.4/index.js",
71107
"is-in-browser": "https://ga.jspm.io/npm:is-in-browser@1.1.3/dist/index.js",
72108
"isarray": "https://ga.jspm.io/npm:isarray@0.0.1/index.js",
73109
"jsesc": "https://ga.jspm.io/npm:jsesc@2.5.2/jsesc.js",
74-
"jss": "https://ga.jspm.io/npm:jss@10.9.2/dist/dev.jss.cjs.js",
110+
"jss": "https://ga.jspm.io/npm:jss@10.9.2/dist/jss.cjs.js",
75111
"jss-plugin-camel-case": "https://ga.jspm.io/npm:jss-plugin-camel-case@10.9.2/dist/jss-plugin-camel-case.cjs.js",
76-
"jss-plugin-compose": "https://ga.jspm.io/npm:jss-plugin-compose@10.9.2/dist/dev.jss-plugin-compose.cjs.js",
112+
"jss-plugin-compose": "https://ga.jspm.io/npm:jss-plugin-compose@10.9.2/dist/jss-plugin-compose.cjs.js",
77113
"jss-plugin-default-unit": "https://ga.jspm.io/npm:jss-plugin-default-unit@10.9.2/dist/jss-plugin-default-unit.cjs.js",
78114
"jss-plugin-expand": "https://ga.jspm.io/npm:jss-plugin-expand@10.9.2/dist/jss-plugin-expand.cjs.js",
79-
"jss-plugin-extend": "https://ga.jspm.io/npm:jss-plugin-extend@10.9.2/dist/dev.jss-plugin-extend.cjs.js",
115+
"jss-plugin-extend": "https://ga.jspm.io/npm:jss-plugin-extend@10.9.2/dist/jss-plugin-extend.cjs.js",
80116
"jss-plugin-global": "https://ga.jspm.io/npm:jss-plugin-global@10.9.2/dist/jss-plugin-global.cjs.js",
81-
"jss-plugin-nested": "https://ga.jspm.io/npm:jss-plugin-nested@10.9.2/dist/dev.jss-plugin-nested.cjs.js",
117+
"jss-plugin-nested": "https://ga.jspm.io/npm:jss-plugin-nested@10.9.2/dist/jss-plugin-nested.cjs.js",
82118
"jss-plugin-props-sort": "https://ga.jspm.io/npm:jss-plugin-props-sort@10.9.2/dist/jss-plugin-props-sort.cjs.js",
83-
"jss-plugin-rule-value-function": "https://ga.jspm.io/npm:jss-plugin-rule-value-function@10.9.2/dist/dev.jss-plugin-rule-value-function.cjs.js",
119+
"jss-plugin-rule-value-function": "https://ga.jspm.io/npm:jss-plugin-rule-value-function@10.9.2/dist/jss-plugin-rule-value-function.cjs.js",
84120
"jss-plugin-rule-value-observable": "https://ga.jspm.io/npm:jss-plugin-rule-value-observable@10.9.2/dist/jss-plugin-rule-value-observable.cjs.js",
85-
"jss-plugin-template": "https://ga.jspm.io/npm:jss-plugin-template@10.9.2/dist/dev.jss-plugin-template.cjs.js",
121+
"jss-plugin-template": "https://ga.jspm.io/npm:jss-plugin-template@10.9.2/dist/jss-plugin-template.cjs.js",
86122
"jss-plugin-vendor-prefixer": "https://ga.jspm.io/npm:jss-plugin-vendor-prefixer@10.9.2/dist/jss-plugin-vendor-prefixer.cjs.js",
87123
"jss-preset-default": "https://ga.jspm.io/npm:jss-preset-default@10.9.2/dist/jss-preset-default.cjs.js",
88124
"lodash.isequal": "https://ga.jspm.io/npm:lodash.isequal@4.5.0/index.js",
89-
"mini-create-react-context": "https://ga.jspm.io/npm:mini-create-react-context@0.4.1/dist/cjs/dev.index.js",
125+
"media-typer": "https://ga.jspm.io/npm:media-typer@0.3.0/index.js",
126+
"merge-descriptors": "https://ga.jspm.io/npm:merge-descriptors@1.0.1/index.js",
127+
"methods": "https://ga.jspm.io/npm:methods@1.1.2/index.js",
128+
"mime": "https://ga.jspm.io/npm:mime@1.6.0/mime.js",
129+
"mime-db": "https://ga.jspm.io/npm:mime-db@1.52.0/index.js",
130+
"mime-types": "https://ga.jspm.io/npm:mime-types@2.1.35/index.js",
131+
"mini-create-react-context": "https://ga.jspm.io/npm:mini-create-react-context@0.4.1/dist/cjs/index.js",
132+
"ms": "https://ga.jspm.io/npm:ms@2.0.0/index.js",
133+
"negotiator": "https://ga.jspm.io/npm:negotiator@0.6.3/index.js",
134+
"net": "node:net",
90135
"node:os": "node:os",
91136
"node:process": "node:process",
92137
"node:tty": "node:tty",
93138
"object-assign": "https://ga.jspm.io/npm:object-assign@4.1.1/index.js",
139+
"object-inspect": "https://ga.jspm.io/npm:object-inspect@1.12.3/index.js",
140+
"on-finished": "https://ga.jspm.io/npm:on-finished@2.4.1/index.js",
141+
"on-headers": "https://ga.jspm.io/npm:on-headers@1.0.2/index.js",
142+
"parseurl": "https://ga.jspm.io/npm:parseurl@1.3.3/index.js",
94143
"path": "node:path",
95-
"path-to-regexp": "https://ga.jspm.io/npm:path-to-regexp@1.8.0/index.js",
144+
"path-to-regexp": "https://ga.jspm.io/npm:path-to-regexp@0.1.7/index.js",
96145
"prettier/": "https://ga.jspm.io/npm:prettier@2.8.4/",
97146
"process": "node:process",
98-
"prop-types": "https://ga.jspm.io/npm:prop-types@15.8.1/dev.index.js",
147+
"prop-types": "https://ga.jspm.io/npm:prop-types@15.8.1/index.js",
99148
"property-information/find": "https://ga.jspm.io/npm:property-information@5.6.0/find.js",
100149
"property-information/html": "https://ga.jspm.io/npm:property-information@5.6.0/html.js",
101150
"property-information/svg": "https://ga.jspm.io/npm:property-information@5.6.0/svg.js",
102-
"react-is": "https://ga.jspm.io/npm:react-is@16.13.1/dev.index.js",
151+
"proxy-addr": "https://ga.jspm.io/npm:proxy-addr@2.0.7/index.js",
152+
"qs": "https://ga.jspm.io/npm:qs@6.11.0/lib/index.js",
153+
"querystring": "node:querystring",
154+
"range-parser": "https://ga.jspm.io/npm:range-parser@1.2.1/index.js",
155+
"raw-body": "https://ga.jspm.io/npm:raw-body@2.5.1/index.js",
156+
"react-is": "https://ga.jspm.io/npm:react-is@16.13.1/index.js",
103157
"repeat-string": "https://ga.jspm.io/npm:repeat-string@1.6.1/index.js",
104-
"resolve-pathname": "https://ga.jspm.io/npm:resolve-pathname@3.0.0/dev.index.js",
105-
"scheduler": "https://ga.jspm.io/npm:scheduler@0.20.2/dev.index.js",
106-
"scheduler/tracing": "https://ga.jspm.io/npm:scheduler@0.20.2/dev.tracing.js",
158+
"resolve-pathname": "https://ga.jspm.io/npm:resolve-pathname@3.0.0/index.js",
159+
"safe-buffer": "https://ga.jspm.io/npm:safe-buffer@5.2.1/index.js",
160+
"safer-buffer": "https://ga.jspm.io/npm:safer-buffer@2.1.2/safer.js",
161+
"scheduler": "https://ga.jspm.io/npm:scheduler@0.20.2/index.js",
162+
"send": "https://ga.jspm.io/npm:send@0.18.0/index.js",
163+
"serve-static": "https://ga.jspm.io/npm:serve-static@1.15.0/index.js",
164+
"setprototypeof": "https://ga.jspm.io/npm:setprototypeof@1.2.0/index.js",
165+
"side-channel": "https://ga.jspm.io/npm:side-channel@1.0.4/index.js",
107166
"space-separated-tokens": "https://ga.jspm.io/npm:space-separated-tokens@1.1.5/index.js",
167+
"statuses": "https://ga.jspm.io/npm:statuses@2.0.1/index.js",
168+
"stream": "node:stream",
169+
"string_decoder": "node:string_decoder",
108170
"stringify-entities": "https://ga.jspm.io/npm:stringify-entities@2.0.0/index.js",
109171
"symbol-observable": "https://ga.jspm.io/npm:symbol-observable@1.2.0/lib/index.js",
110-
"tiny-invariant": "https://ga.jspm.io/npm:tiny-invariant@1.3.1/dist/dev.tiny-invariant.cjs.js",
111-
"tiny-warning": "https://ga.jspm.io/npm:tiny-warning@1.0.3/dist/dev.tiny-warning.cjs.js",
172+
"tiny-invariant": "https://ga.jspm.io/npm:tiny-invariant@1.3.1/dist/tiny-invariant.cjs.js",
173+
"tiny-warning": "https://ga.jspm.io/npm:tiny-warning@1.0.3/dist/tiny-warning.cjs.js",
112174
"to-fast-properties": "https://ga.jspm.io/npm:to-fast-properties@2.0.0/index.js",
175+
"toidentifier": "https://ga.jspm.io/npm:toidentifier@1.0.1/index.js",
176+
"tty": "node:tty",
177+
"type-is": "https://ga.jspm.io/npm:type-is@1.6.18/index.js",
113178
"unist-util-is": "https://ga.jspm.io/npm:unist-util-is@2.1.3/index.js",
114-
"value-equal": "https://ga.jspm.io/npm:value-equal@1.0.1/dev.index.js",
115-
"xtend": "https://ga.jspm.io/npm:xtend@4.0.2/immutable.js"
179+
"unpipe": "https://ga.jspm.io/npm:unpipe@1.0.0/index.js",
180+
"url": "node:url",
181+
"util": "node:util",
182+
"utils-merge": "https://ga.jspm.io/npm:utils-merge@1.0.1/index.js",
183+
"value-equal": "https://ga.jspm.io/npm:value-equal@1.0.1/index.js",
184+
"vary": "https://ga.jspm.io/npm:vary@1.1.2/index.js",
185+
"xtend": "https://ga.jspm.io/npm:xtend@4.0.2/immutable.js",
186+
"zlib": "node:zlib"
187+
},
188+
"https://ga.jspm.io/npm:basic-auth@2.0.1/": {
189+
"safe-buffer": "https://ga.jspm.io/npm:safe-buffer@5.1.2/index.js"
190+
},
191+
"https://ga.jspm.io/npm:morgan@1.10.0/": {
192+
"on-finished": "https://ga.jspm.io/npm:on-finished@2.3.0/index.js"
193+
},
194+
"https://ga.jspm.io/npm:react-router@5.2.1/": {
195+
"path-to-regexp": "https://ga.jspm.io/npm:path-to-regexp@1.8.0/index.js"
196+
},
197+
"https://ga.jspm.io/npm:send@0.18.0/": {
198+
"ms": "https://ga.jspm.io/npm:ms@2.1.3/index.js"
116199
}
117200
}
118201
}

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"name": "jspm-node-import-map-loader",
33
"type": "module",
4+
"scripts": {
5+
"test": "node --loader ./loader.js test.js",
6+
"server": "node --loader ./loader.js test-server.js"
7+
},
48
"dependencies": {
59
"@jspm/import-map": "^1.0.5",
610
"fs-extra": "^11.1.0",

test-server.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import express from "express";
2+
import morgan from "morgan";
3+
import { readFileSync } from "node:fs";
4+
import { fileURLToPath } from "node:url";
5+
import { join } from "node:path";
6+
7+
const app = express();
8+
app.use(morgan("tiny"));
9+
app.get("/", (request, response) => {
10+
response.send("Hi there");
11+
});
12+
13+
app.get("/map", (request, response) => {
14+
const nodeImportMapPath = join(
15+
fileURLToPath(new URL(".", import.meta.url)),
16+
"node.importmap"
17+
);
18+
response.json(
19+
JSON.parse(readFileSync(nodeImportMapPath, { encoding: "utf8" }))
20+
);
21+
});
22+
23+
app.listen(3000, () => {
24+
console.log("Listen on the port 3000...");
25+
});

0 commit comments

Comments
 (0)