Commit 8af02018 authored by HMonroy's avatar HMonroy Committed by MusikAnimal
Browse files

Set node server

parent 9c1acd89
/**
* 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}/ ` );
} );
......@@ -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",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment