Commit 2ce61b61 authored by Emmanuel Raviart's avatar Emmanuel Raviart

Initial commit

parents
Pipeline #133 failed with stages
in 23 seconds
{
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-json-strings",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-logical-assignment-operators",
"@babel/plugin-proposal-optional-chaining",
[
"@babel/plugin-proposal-pipeline-operator",
{
"proposal": "minimal"
}
],
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-do-expressions",
"@babel/plugin-proposal-function-bind"
]
}
{
"env": {
"node": true
},
"globals": {
"Promise": true,
"Set": true
},
"parser": "babel-eslint",
"plugins": [
"html"
],
"rules": {
"comma-dangle": ["error", "always-multiline"],
"extends": "eslint:recommended",
"max-len": ["error", {"code": 120, "ignoreRegExpLiterals": true, "ignoreUrls": true, "tabWidth": 2}],
"no-undef": "error",
"no-unused-expressions": "error",
"no-unused-vars": "error",
"no-use-before-define": ["error", "nofunc"],
"quotes": ["error", "double", "avoid-escape"],
"semi": ["error", "never"]
}
}
/__sapper__
.DS_Store
node_modules
yarn-error.log
\ No newline at end of file
# Eurhisfirm-SiteLinks-Server
Web service providing a MediaWiki-compatible API for sitelinks
By: Emmanuel Raviart <emmanuel@raviart.com>
Copyright (C) 2018 École d’économie de Paris (PSE)
https://gitlab.huma-num.fr/eurhisfirm/eurhisfirm-sitelinks-server
> Eurhisfirm-SiteLinks-Server is free software; you can redistribute it and/or modify
> it under the terms of the GNU Affero General Public License as
> published by the Free Software Foundation, either version 3 of the
> License, or (at your option) any later version.
>
> Eurhisfirm-SiteLinks-Server is distributed in the hope that it will be useful,
> but WITHOUT ANY WARRANTY; without even the implied warranty of
> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> GNU Affero General Public License for more details.
>
> You should have received a copy of the GNU Affero General Public License
> along with this program. If not, see <http://www.gnu.org/licenses/>.
# Eurhisfirm-SiteLinks-Server
_Web service providing a MediaWiki-compatible API for sitelinks_
## Installation & Configuration
```bash
git clone https://gitlab.huma-num.fr/eurhisfirm/eurhisfirm-sitelinks-server.git
cd eurhisfirm-sitelinks-server/
npm install
```
## Running Server...
### ... in development mode
```bash
npm run dev
```
### ... in production mode
```bash
npm run build
```
This diff is collapsed.
{
"name": "eurhisfirm-sitelinks-server",
"description": "Web service providing a MediaWiki-compatible API for sitelinks",
"version": "0.0.1",
"author": "Emmanuel Raviart <emmanuel@raviart.com>",
"license": "AGPL-3.0-or-later",
"repository": {
"type": "git",
"url": "https://gitlab.huma-num.fr/eurhisfirm/sitelink-server.git"
},
"keywords": [
"mediawiki",
"sitelink",
"wikibase"
],
"scripts": {
"dev": "sapper dev",
"build": "sapper build",
"export": "sapper export",
"start": "node __sapper__/build"
},
"dependencies": {
"compression": "^1.7.1",
"polka": "^0.5.1",
"sirv": "^0.2.0"
},
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.2",
"@babel/plugin-proposal-do-expressions": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-bind": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.1.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.4",
"eslint": "^5.7.0",
"eslint-loader": "^2.1.1",
"eslint-plugin-html": "^5.0.0",
"morgan": "^1.9.1",
"npm-run-all": "^4.1.2",
"sapper": "^0.24.0",
"svelte": "^2.0.0",
"svelte-loader": "^2.9.0",
"webpack": "^4.7.0"
}
}
import * as sapper from "../__sapper__/client"
sapper.start({
target: document.querySelector("#sapper"),
})
\ No newline at end of file
<svelte:head>
<title>{status}</title>
</svelte:head>
<h1>{status}</h1>
<p>{error.message}</p>
{#if dev && error.stack}
<pre>{error.stack}</pre>
{/if}
<style>
h1, p {
margin: 0 auto;
}
h1 {
font-size: 2.8em;
font-weight: 700;
margin: 0 0 0.5em 0;
}
p {
margin: 1em auto;
}
@media (min-width: 480px) {
h1 {
font-size: 4em;
}
}
</style>
<script>
export default {
helpers: {
dev: process.env.NODE_ENV === "development",
}
}
</script>
const entriesRegexps = [
/^(lei)\/([0-9A-Z]{20})$/,
]
export async function get(req, res) {
const { action } = req.query
if (action === "query") {
// Cf https://www.mediawiki.org/wiki/API:Query
const { /* converttitles, */ format, prop, /* redirects, */ titles } = req.query
if (format === "json" && prop === "info") {
// Cf https://www.mediawiki.org/w/api.php?action=help&modules=query%2Binfo
if (!titles) {
titles = ""
}
let entry = null
for (let regexp of entriesRegexps) {
const match = regexp.exec(titles)
if (match !== null) {
entry = {
kind: match[1],
slug: match[2],
}
break
}
}
if (entry === null) {
res.writeHead(200, {
"Content-Type": "application/json",
})
return res.end(
JSON.stringify(
{
batchcomplete: "",
query: {
pages: {
"-1": {
ns: 0, // namespace ID
title: titles,
missing: "", // page not found
contentmodel: "json",
pagelanguage: "en",
pagelanguagehtmlcode: "en",
pagelanguagedir: "ltr",
},
},
},
},
null,
2
)
)
}
const query = {
pages: {
[entry.slug]: {
pageid: entry.slug, // Should be a number.
ns: 0, // namespace 0 (default) for entry
title: `${entry.kind}/${entry.slug}`,
contentmodel: "json",
pagelanguage: "en",
pagelanguagehtmlcode: "en",
pagelanguagedir: "ltr",
// touched "2018-10-24T20:45:29Z"
// lastrevid 153345869
// length 56564
},
},
}
res.writeHead(200, {
"Content-Type": "application/json",
})
return res.end(
JSON.stringify(
{
batchcomplete: "",
query,
},
null,
2
)
)
} else {
res.writeHead(400, {
"Content-Type": "application/json",
})
res.end(
JSON.stringify(
{
error: {
code: 400,
message: `Unexpected options for action: ${action}.`,
},
},
null,
2
)
)
}
} else {
res.writeHead(400, {
"Content-Type": "application/json",
})
res.end(
JSON.stringify(
{
error: {
code: 400,
message: `Unexpected action: ${action}.`,
},
},
null,
2
)
)
}
}
import sirv from "sirv"
import polka from "polka"
import compression from "compression"
import * as sapper from "../__sapper__/server"
const { PORT, NODE_ENV } = process.env
const dev = NODE_ENV === "development"
const app = polka()
if (dev) {
// Add logging.
const morgan = require("morgan")
app.use(morgan("dev"))
}
app
.use(
compression({ threshold: 0 }),
sirv("static", { dev }),
sapper.middleware()
)
.listen(PORT, err => {
if (err) console.log("error", err)
})
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
%sapper.base%
<link rel="icon" type="image/png" href="favicon.png">
<!-- Sapper generates a <style> tag containing critical CSS
for the current page. CSS for the rest of the app is
lazily loaded when it precaches secondary pages -->
%sapper.styles%
<!-- This contains the contents of the <svelte:head> component, if
the current page has one -->
%sapper.head%
</head>
<body>
<!-- The application will be rendered inside this element,
because `app/client.js` references it -->
<div id="sapper">%sapper.html%</div>
<!-- Sapper creates a <script> tag containing `app/client.js`
and anything else it needs to hydrate the app and
initialise the router -->
%sapper.scripts%
</body>
</html>
const webpack = require("webpack")
const config = require("sapper/config/webpack.js")
const pkg = require("./package.json")
const clientEntry = config.client.entry()
clientEntry.main = ["@babel/polyfill", clientEntry.main]
const serverEntry = config.server.entry()
serverEntry.server = ["@babel/polyfill", serverEntry.server]
const mode = process.env.NODE_ENV || "production"
const dev = mode === "development"
module.exports = {
client: {
entry: clientEntry,
output: config.client.output(),
resolve: {
extensions: [".js", ".json", ".html"],
mainFields: ["svelte", "module", "browser", "main"],
},
module: {
rules: [
{
test: /\.html$/,
use: [
"babel-loader",
{
loader: "svelte-loader",
options: {
dev,
hydratable: true,
hotReload: true,
},
},
{
loader: "eslint-loader",
options: {
emitWarning: dev,
fix: true,
},
},
],
},
],
},
mode,
plugins: [
dev && new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
"process.browser": true,
"process.env.NODE_ENV": JSON.stringify(mode),
}),
].filter(Boolean),
devtool: dev && "inline-source-map",
},
server: {
entry: serverEntry,
output: config.server.output(),
target: "node",
resolve: {
extensions: [".js", ".json", ".html"],
mainFields: ["svelte", "module", "browser", "main"],
},
externals: Object.keys(pkg.dependencies).concat("encoding"),
module: {
rules: [
{
test: /\.html$/,
use: {
loader: "svelte-loader",
options: {
css: false,
generate: "ssr",
dev,
},
},
},
],
},
mode,
performance: {
hints: false, // it doesn't matter if server.js is large
},
},
}
Markdown is supported
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