npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

maple-electron-router

v0.1.10

Published

An electron based router.

Downloads

15

Readme

maple-electron-router

基于electron的服务。(Services based on electron framework.)

npm version

示例(Examples)

项目起步时间不是很长,可能会有一些调整,请求谅解一下^_^.(Project start time is not very long, there may be some adjustments, please understand^_^.)

main.js

const { app, BrowserWindow } = require("electron");
const { Service, Router } = require("maple-electron-router");

// 创建服务(create service)
const server = new Service("app", "maple.hyf");

// 文件组 (file group)
server.files("/", "public", { webRouter: true });

// 设置GET请求 (set GET request)
server.get("/hello", (req, res) => {
    res.send("GET:helloWorld");
})

// 设置PUT请求 (set PUT request)
server.put("/hello", (req, res) => {
    res.send("PUT:helloWorld");
})

// 设置POST请求 (set POST request)
server.post("/hello", (req, res) => {
    res.send("POST:helloWorld");
});

// 中间件 (middleware)
server.use("/hello", (req, res, next) => {
    next();
});

// 设置DELETE请求 (set DELETE request)
server.delete("/hello", (req, res) => {
    res.send("DELETE:helloWorld");
});

// 创建独立路由 (Create independent router)
const router = new Router();

// 设置路由GET请求 (set router GET request)
router.get("/get", (req, res) => {
    res.send({
        text: "HelloWorld!"
    });
});

// 合并路由 (Merge router)
server.use("/router", router);


// 运行窗口
app.whenReady().then(() => {
    const win = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
            nodeIntegration: true
        }
    });
    win.loadURL("app://maple.hyf")
    win.webContents.openDevTools()
})

index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="get-hello"></div>
    <div id="post-hello"></div>
    <div id="post-router"></div>
    <script>

        fetch("/hello", { method: "GET" }).then(async res => {
            const data = await res.text();
            document.getElementById("get-hello").innerHTML = data;
            console.log(data)
        });

        fetch("/hello", { method: "POST", body: JSON.stringify({ data: "post" }) }).then(async res => {
            const data = await res.text();
            document.getElementById("post-hello").innerHTML = data;
            console.log(data)
        });

        fetch("/router/get", { method: "GET" }).then(async res => {
            const data = await res.json();
            document.getElementById("post-router").innerHTML = JSON.stringify(data);
            console.log(data)
        });

    </script>

    <script>
        const { Request } = require("maple-electron-router");

        Request.put("/hello").then((arg) => {
            console.log(arg)
        });

        Request.delete("/hello").then((arg) => {
            console.log(arg)
        });
    </script>
</body>

</html>

安装(Installation)

这是一个node.js模块可通过npm安装.(This is a Node.js module available through the npm registry. )

安装前,下载并安装Electron并且 Electron要求8.0.0或更高。(Before installing, Electron. Electron 8.0.0 or higher is required.)

安装方式 npm install command:

$ npm install maple-electron-router 

(特点)Features

  • 非端口服务(Nonport service)
  • 更好的管理Electron的主进程和渲染进程的交互(Better management of electron main process and rendering process interaction)

(文档:Docs)Service <Constructor>

参数(Params)

  • scheme <string>:协议名(Name of agreement)
  • host <string>:域名地址(Domain name address)
  • privileges <object>
    • secure <boolean>
    • bypassCSP <boolean>
    • allowServiceWorkers <boolean>
    • corsEnabled <boolean>

实例返回一个路由(Instance returns a router)

  • Router

Router

  • use
  • get
  • put
  • post
  • delete
  • files