Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
repos
commtech
AutosuggestSitelink
Commits
8af02018
Commit
8af02018
authored
Dec 15, 2022
by
HMonroy
Committed by
MusikAnimal
Dec 15, 2022
Browse files
Set node server
parent
9c1acd89
Changes
3
Hide whitespace changes
Inline
Side-by-side
bin/server.js
0 → 100755
View file @
8af02018
/**
* Based on https://github.com/wikimedia-gadgets/twinkle/blob/master/scripts/server.js (CC BY-SA 3.0)
*
* Starts a local server, so you can test your code by importing the src/ directory from your local.
* To use, run "node bin/server.js", then in your https://meta.wikimedia.org/wiki/Special:MyPage/global.js,
* add the following:
* mw.loader.load('http://localhost:5501/src/AutosuggestSitelink.js');
*/
/* global process */
const
http
=
require
(
'
http
'
);
const
fs
=
require
(
'
fs
'
);
const
server
=
http
.
createServer
(
(
request
,
response
)
=>
{
const
filePath
=
`.
${
request
.
url
}
`
;
let
contentType
;
if
(
request
.
url
.
endsWith
(
'
.js
'
)
)
{
contentType
=
'
text/javascript
'
;
}
else
if
(
request
.
url
.
endsWith
(
'
.css
'
)
)
{
contentType
=
'
text/css
'
;
}
else
{
contentType
=
'
text/plain
'
;
}
fs
.
readFile
(
filePath
,
(
error
,
content
)
=>
{
if
(
error
)
{
response
.
end
(
`Oops, something went wrong:
${
error
.
code
}
..\n`
);
}
else
{
response
.
writeHead
(
200
,
{
'
Content-Type
'
:
contentType
}
);
response
.
end
(
content
,
'
utf-8
'
);
}
}
);
}
);
const
hostname
=
'
127.0.0.1
'
;
const
port
=
isNaN
(
Number
(
process
.
argv
[
2
]
)
)
?
5501
:
process
.
argv
[
2
];
server
.
listen
(
port
,
hostname
,
()
=>
{
// eslint-disable-next-line no-console
console
.
log
(
`Server running at http://
${
hostname
}
:
${
port
}
/ `
);
}
);
package.json
View file @
8af02018
...
...
@@ -2,12 +2,12 @@
"name"
:
"autosuggest-linking-wikidata"
,
"version"
:
"0.1.0"
,
"description"
:
"A tool to suggest sitelinks between wiki pages and Wikidata items"
,
"main"
:
"AutosuggestSitelink.js"
,
"main"
:
"
src/
AutosuggestSitelink.js"
,
"directories"
:
{
"doc"
:
"docs"
},
"scripts"
:
{
"test"
:
"eslint AutosuggestSitelink.js"
"test"
:
"eslint
bin/ && eslint src/
AutosuggestSitelink.js"
},
"repository"
:
{
"type"
:
"git"
,
...
...
AutosuggestSitelink.js
→
src/
AutosuggestSitelink.js
View file @
8af02018
File moved
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment