apiforge-cli 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +10 -0
  2. package/bin/apiforge.js +19 -0
  3. package/lib/create.js +24 -0
  4. package/package.json +16 -0
  5. package/templates/auth/index.js +67 -0
  6. package/templates/auth/package.json +11 -0
  7. package/templates/cors/index.js +18 -0
  8. package/templates/cors/package.json +10 -0
  9. package/templates/crud/index.js +37 -0
  10. package/templates/crud/package.json +9 -0
  11. package/templates/firebase/index.js +15 -0
  12. package/templates/firebase/package.json +10 -0
  13. package/templates/graphql/index.js +32 -0
  14. package/templates/graphql/package.json +11 -0
  15. package/templates/jwt/index.js +33 -0
  16. package/templates/jwt/package.json +10 -0
  17. package/templates/mongodb/index.js +26 -0
  18. package/templates/mongodb/package.json +10 -0
  19. package/templates/mysql/index.js +27 -0
  20. package/templates/mysql/package.json +10 -0
  21. package/templates/netlify/netlify/functions/index.js +14 -0
  22. package/templates/netlify/package.json +7 -0
  23. package/templates/oauth2/index.js +28 -0
  24. package/templates/oauth2/package.json +11 -0
  25. package/templates/postgres/index.js +30 -0
  26. package/templates/postgres/package.json +10 -0
  27. package/templates/ratelimit/index.js +24 -0
  28. package/templates/ratelimit/package.json +10 -0
  29. package/templates/receiver/index.js +30 -0
  30. package/templates/receiver/package.json +9 -0
  31. package/templates/rest/index.js +22 -0
  32. package/templates/rest/package.json +9 -0
  33. package/templates/sqlite/index.js +23 -0
  34. package/templates/sqlite/package.json +10 -0
  35. package/templates/swagger/index.js +33 -0
  36. package/templates/swagger/package.json +11 -0
  37. package/templates/typescript/index.ts +16 -0
  38. package/templates/typescript/package.json +14 -0
  39. package/templates/upload/index.js +30 -0
  40. package/templates/upload/package.json +10 -0
  41. package/templates/vercel/api/index.js +8 -0
  42. package/templates/vercel/package.json +9 -0
  43. package/templates/websocket/index.js +28 -0
  44. package/templates/websocket/package.json +10 -0
  45. package/templates/workers/index.js +17 -0
  46. package/templates/workers/package.json +7 -0
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # APIForge 🚀
2
+
3
+ API generator with ready-made templates for quickly creating projects.
4
+
5
+ APIForge lets you create different types of APIs using a single command.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install -g apiforge
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { createProject } from "../lib/create.js";
4
+
5
+ const args = process.argv.slice(2);
6
+
7
+ if (args[0] === "-create") {
8
+ const type = args[1];
9
+ const name = args[2];
10
+
11
+ if (!type || !name) {
12
+ console.log("Uso: apiforge -create <tipo> <nombre>");
13
+ process.exit(1);
14
+ }
15
+
16
+ createProject(type, name);
17
+ } else {
18
+ console.log("Comando no reconocido");
19
+ }
package/lib/create.js ADDED
@@ -0,0 +1,24 @@
1
+ import fs from "fs-extra";
2
+ import path from "path";
3
+
4
+ export function createProject(type, name) {
5
+ const template = path.join(
6
+ process.cwd(),
7
+ "templates",
8
+ type
9
+ );
10
+
11
+ const destination = path.join(
12
+ process.cwd(),
13
+ name
14
+ );
15
+
16
+ if (!fs.existsSync(template)) {
17
+ console.log("Plantilla no encontrada");
18
+ return;
19
+ }
20
+
21
+ fs.copySync(template, destination);
22
+
23
+ console.log(`Proyecto creado: ${name}`);
24
+ }
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "apiforge-cli",
3
+ "version": "1.0.1",
4
+ "description": "CLI for automatically creating APIs",
5
+ "type": "module",
6
+ "bin": {
7
+ "apiforge": "./bin/apiforge.js"
8
+
9
+ },
10
+ "dependencies": {
11
+ "chalk": "^5.0.0",
12
+ "commander": "^12.0.0",
13
+ "fs-extra": "^11.0.0"
14
+
15
+ }
16
+ }
@@ -0,0 +1,67 @@
1
+ import express from "express";
2
+ import jwt from "jsonwebtoken";
3
+ import bcrypt from "bcrypt";
4
+
5
+ const app = express();
6
+
7
+ app.use(express.json());
8
+
9
+ const SECRET = "apiforge-secret";
10
+
11
+ const users = [];
12
+
13
+ app.post("/register", async (req, res) => {
14
+
15
+ const password = await bcrypt.hash(
16
+ req.body.password,
17
+ 10
18
+ );
19
+
20
+ users.push({
21
+ username: req.body.username,
22
+ password,
23
+ role: "user"
24
+ });
25
+
26
+ res.json({
27
+ created: true
28
+ });
29
+
30
+ });
31
+
32
+ app.post("/login", async (req, res) => {
33
+
34
+ const user = users.find(
35
+ u => u.username === req.body.username
36
+ );
37
+
38
+ if (!user) {
39
+ return res.status(404).json({
40
+ error: "User not found"
41
+ });
42
+ }
43
+
44
+ const token = jwt.sign(
45
+ {
46
+ username: user.username,
47
+ role: user.role
48
+ },
49
+ SECRET
50
+ );
51
+
52
+ res.json({
53
+ token
54
+ });
55
+
56
+ });
57
+
58
+ app.get("/", (req, res) => {
59
+ res.json({
60
+ api: "Auth API",
61
+ status: "online"
62
+ });
63
+ });
64
+
65
+ app.listen(3000, () => {
66
+ console.log("Auth API funcionando");
67
+ });
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "auth-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "jsonwebtoken": "^9.0.2",
9
+ "bcrypt": "^5.1.1"
10
+ }
11
+ }
@@ -0,0 +1,18 @@
1
+ import express from "express";
2
+ import cors from "cors";
3
+
4
+ const app = express();
5
+
6
+ app.use(cors());
7
+ app.use(express.json());
8
+
9
+ app.get("/", (req, res) => {
10
+ res.json({
11
+ api: "CORS API",
12
+ status: "online"
13
+ });
14
+ });
15
+
16
+ app.listen(3000, () => {
17
+ console.log("CORS API funcionando");
18
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "cors-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "cors": "^2.8.5"
9
+ }
10
+ }
@@ -0,0 +1,37 @@
1
+ import express from "express";
2
+
3
+ const app = express();
4
+
5
+ app.use(express.json());
6
+
7
+ let users = [];
8
+
9
+ app.get("/users", (req, res) => {
10
+ res.json(users);
11
+ });
12
+
13
+ app.post("/users", (req, res) => {
14
+ const user = req.body;
15
+ users.push(user);
16
+
17
+ res.json({
18
+ created: true,
19
+ user
20
+ });
21
+ });
22
+
23
+ app.put("/users/:id", (req, res) => {
24
+ users[req.params.id] = req.body;
25
+
26
+ res.json({
27
+ updated: true
28
+ });
29
+ });
30
+
31
+ app.delete("/users/:id", (req, res) => {
32
+ users.splice(req.params.id, 1);
33
+
34
+ res.json({
35
+ deleted: true
36
+ });
37
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "crud-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0"
8
+ }
9
+ }
@@ -0,0 +1,15 @@
1
+ import { onRequest } from "firebase-functions/v2/https";
2
+ import express from "express";
3
+
4
+ const app = express();
5
+
6
+ app.use(express.json());
7
+
8
+ app.get("/", (req, res) => {
9
+ res.json({
10
+ api: "Firebase Functions API",
11
+ status: "online"
12
+ });
13
+ });
14
+
15
+ export const api = onRequest(app);
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "firebase-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "firebase-functions": "^6.0.0",
8
+ "express": "^5.0.0"
9
+ }
10
+ }
@@ -0,0 +1,32 @@
1
+ import express from "express";
2
+ import { graphqlHTTP } from "express-graphql";
3
+ import {
4
+ buildSchema
5
+ } from "graphql";
6
+
7
+ const app = express();
8
+
9
+ const schema = buildSchema(`
10
+ type Query {
11
+ hello: String
12
+ }
13
+ `);
14
+
15
+ const root = {
16
+ hello() {
17
+ return "GraphQL API funcionando";
18
+ }
19
+ };
20
+
21
+ app.use(
22
+ "/graphql",
23
+ graphqlHTTP({
24
+ schema,
25
+ rootValue: root,
26
+ graphiql: true
27
+ })
28
+ );
29
+
30
+ app.listen(3000, () => {
31
+ console.log("GraphQL API lista");
32
+ });
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "graphql-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "graphql": "^16.0.0",
9
+ "express-graphql": "^0.12.0"
10
+ }
11
+ }
@@ -0,0 +1,33 @@
1
+ import express from "express";
2
+ import jwt from "jsonwebtoken";
3
+
4
+ const app = express();
5
+
6
+ app.use(express.json());
7
+
8
+ const SECRET = "apiforge-secret";
9
+
10
+ app.post("/login", (req, res) => {
11
+ const { user } = req.body;
12
+
13
+ const token = jwt.sign(
14
+ { user },
15
+ SECRET,
16
+ { expiresIn: "1h" }
17
+ );
18
+
19
+ res.json({
20
+ token
21
+ });
22
+ });
23
+
24
+ app.get("/", (req, res) => {
25
+ res.json({
26
+ api: "JWT API",
27
+ status: "online"
28
+ });
29
+ });
30
+
31
+ app.listen(3000, () => {
32
+ console.log("JWT API funcionando");
33
+ });
@@ -0,0 +1,10 @@
1
+ cat > templates/jwt/index.js{
2
+ "name": "jwt-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "jsonwebtoken": "^9.0.2"
9
+ }
10
+ }
@@ -0,0 +1,26 @@
1
+ import express from "express";
2
+ import mongoose from "mongoose";
3
+
4
+ const app = express();
5
+
6
+ app.use(express.json());
7
+
8
+ mongoose.connect("mongodb://127.0.0.1:27017/apiforge");
9
+
10
+ const User = mongoose.model(
11
+ "User",
12
+ new mongoose.Schema({
13
+ name: String
14
+ })
15
+ );
16
+
17
+ app.get("/", (req, res) => {
18
+ res.json({
19
+ api: "MongoDB API",
20
+ status: "online"
21
+ });
22
+ });
23
+
24
+ app.listen(3000, () => {
25
+ console.log("MongoDB API funcionando");
26
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "mongodb-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "mongoose": "^8.0.0"
9
+ }
10
+ }
@@ -0,0 +1,27 @@
1
+ import express from "express";
2
+ import mysql from "mysql2/promise";
3
+
4
+ const app = express();
5
+
6
+ app.use(express.json());
7
+
8
+ const db = await mysql.createConnection({
9
+ host: "localhost",
10
+ user: "root",
11
+ password: "",
12
+ database: "apiforge"
13
+ });
14
+
15
+ app.get("/", async (req, res) => {
16
+ const [rows] = await db.query("SELECT NOW() AS serverTime");
17
+
18
+ res.json({
19
+ api: "MySQL API",
20
+ status: "online",
21
+ serverTime: rows[0].serverTime
22
+ });
23
+ });
24
+
25
+ app.listen(3000, () => {
26
+ console.log("MySQL API funcionando");
27
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "mysql-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "mysql2": "^3.0.0"
9
+ }
10
+ }
@@ -0,0 +1,14 @@
1
+ export async function handler(event) {
2
+
3
+ return {
4
+ statusCode: 200,
5
+ headers: {
6
+ "Content-Type": "application/json"
7
+ },
8
+ body: JSON.stringify({
9
+ api: "Netlify Functions API",
10
+ status: "online"
11
+ })
12
+ };
13
+
14
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "netlify-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "netlify/functions/index.js",
6
+ "dependencies": {}
7
+ }
@@ -0,0 +1,28 @@
1
+ import express from "express";
2
+ import passport from "passport";
3
+ import { Strategy as OAuth2Strategy } from "passport-oauth2";
4
+
5
+ const app = express();
6
+
7
+ passport.use(new OAuth2Strategy({
8
+ authorizationURL: "https://example.com/oauth/authorize",
9
+ tokenURL: "https://example.com/oauth/token",
10
+ clientID: "CLIENT_ID",
11
+ clientSecret: "CLIENT_SECRET",
12
+ callbackURL: "/auth/callback"
13
+ }, (accessToken, refreshToken, profile, done) => {
14
+ return done(null, { accessToken });
15
+ }));
16
+
17
+ app.use(passport.initialize());
18
+
19
+ app.get("/", (req, res) => {
20
+ res.json({
21
+ api: "OAuth2 API",
22
+ status: "online"
23
+ });
24
+ });
25
+
26
+ app.listen(3000, () => {
27
+ console.log("OAuth2 API funcionando");
28
+ });
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "oauth2-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "passport": "^0.7.0",
9
+ "passport-oauth2": "^1.8.0"
10
+ }
11
+ }
@@ -0,0 +1,30 @@
1
+ import express from "express";
2
+ import { Client } from "pg";
3
+
4
+ const app = express();
5
+
6
+ app.use(express.json());
7
+
8
+ const db = new Client({
9
+ host: "localhost",
10
+ port: 5432,
11
+ user: "postgres",
12
+ password: "password",
13
+ database: "apiforge"
14
+ });
15
+
16
+ await db.connect();
17
+
18
+ app.get("/", async (req, res) => {
19
+ const result = await db.query("SELECT NOW()");
20
+
21
+ res.json({
22
+ api: "PostgreSQL API",
23
+ status: "online",
24
+ serverTime: result.rows[0].now
25
+ });
26
+ });
27
+
28
+ app.listen(3000, () => {
29
+ console.log("PostgreSQL API funcionando");
30
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "postgres-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "pg": "^8.13.0"
9
+ }
10
+ }
@@ -0,0 +1,24 @@
1
+ import express from "express";
2
+ import rateLimit from "express-rate-limit";
3
+
4
+ const app = express();
5
+
6
+ app.use(express.json());
7
+
8
+ const limiter = rateLimit({
9
+ windowMs: 60 * 1000,
10
+ max: 10
11
+ });
12
+
13
+ app.use(limiter);
14
+
15
+ app.get("/", (req, res) => {
16
+ res.json({
17
+ api: "Rate Limit API",
18
+ status: "online"
19
+ });
20
+ });
21
+
22
+ app.listen(3000, () => {
23
+ console.log("Rate Limit API funcionando");
24
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "ratelimit-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "express-rate-limit": "^7.0.0"
9
+ }
10
+ }
@@ -0,0 +1,30 @@
1
+ import express from "express";
2
+
3
+ const app = express();
4
+
5
+ app.use(express.json());
6
+
7
+ app.post("/api/data", (req, res) => {
8
+
9
+ console.log("Datos recibidos:");
10
+ console.log(req.body);
11
+
12
+ res.json({
13
+ success: true,
14
+ received: req.body
15
+ });
16
+
17
+ });
18
+
19
+ app.get("/", (req, res) => {
20
+
21
+ res.json({
22
+ api: "HTTP Receiver",
23
+ status: "online"
24
+ });
25
+
26
+ });
27
+
28
+ app.listen(3000, () => {
29
+ console.log("Receiver API en puerto 3000");
30
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "receiver-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0"
8
+ }
9
+ }
@@ -0,0 +1,22 @@
1
+ import express from "express";
2
+
3
+ const app = express();
4
+
5
+ app.use(express.json());
6
+
7
+ app.get("/", (req, res) => {
8
+ res.json({
9
+ api: "REST API",
10
+ status: "online"
11
+ });
12
+ });
13
+
14
+ app.post("/api/data", (req, res) => {
15
+ res.json({
16
+ received: req.body
17
+ });
18
+ });
19
+
20
+ app.listen(3000, () => {
21
+ console.log("REST API on port 3000");
22
+ });
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "rest-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0"
8
+ }
9
+ }
@@ -0,0 +1,23 @@
1
+ import express from "express";
2
+ import sqlite3 from "sqlite3";
3
+
4
+ const app = express();
5
+
6
+ app.use(express.json());
7
+
8
+ const db = new sqlite3.Database("database.db");
9
+
10
+ db.serialize(() => {
11
+ db.run("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)");
12
+ });
13
+
14
+ app.get("/", (req, res) => {
15
+ res.json({
16
+ api: "SQLite API",
17
+ status: "online"
18
+ });
19
+ });
20
+
21
+ app.listen(3000, () => {
22
+ console.log("SQLite API funcionando");
23
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "sqlite-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "sqlite3": "^5.1.7"
9
+ }
10
+ }
@@ -0,0 +1,33 @@
1
+ import express from "express";
2
+ import swaggerUi from "swagger-ui-express";
3
+ import swaggerJsdoc from "swagger-jsdoc";
4
+
5
+ const app = express();
6
+
7
+ const swaggerSpec = swaggerJsdoc({
8
+ definition: {
9
+ openapi: "3.0.0",
10
+ info: {
11
+ title: "APIForge API",
12
+ version: "1.0.0"
13
+ }
14
+ },
15
+ apis: []
16
+ });
17
+
18
+ app.use(
19
+ "/docs",
20
+ swaggerUi.serve,
21
+ swaggerUi.setup(swaggerSpec)
22
+ );
23
+
24
+ app.get("/", (req, res) => {
25
+ res.json({
26
+ api: "Swagger API",
27
+ status: "online"
28
+ });
29
+ });
30
+
31
+ app.listen(3000, () => {
32
+ console.log("Swagger API funcionando");
33
+ });
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "swagger-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "swagger-ui-express": "^5.0.0",
9
+ "swagger-jsdoc": "^6.2.0"
10
+ }
11
+ }
@@ -0,0 +1,16 @@
1
+ import express from "express";
2
+
3
+ const app = express();
4
+
5
+ app.use(express.json());
6
+
7
+ app.get("/", (req, res) => {
8
+ res.json({
9
+ api: "TypeScript API",
10
+ status: "online"
11
+ });
12
+ });
13
+
14
+ app.listen(3000, () => {
15
+ console.log("TypeScript API funcionando");
16
+ });
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "typescript-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0"
8
+ },
9
+ "devDependencies": {
10
+ "typescript": "^5.0.0",
11
+ "tsx": "^4.0.0",
12
+ "@types/express": "^5.0.0"
13
+ }
14
+ }
@@ -0,0 +1,30 @@
1
+ import express from "express";
2
+ import multer from "multer";
3
+
4
+ const app = express();
5
+
6
+ const upload = multer({
7
+ dest: "uploads/"
8
+ });
9
+
10
+ app.post("/upload", upload.single("file"), (req, res) => {
11
+
12
+ res.json({
13
+ success: true,
14
+ file: req.file
15
+ });
16
+
17
+ });
18
+
19
+ app.get("/", (req, res) => {
20
+
21
+ res.json({
22
+ api: "Upload API",
23
+ status: "online"
24
+ });
25
+
26
+ });
27
+
28
+ app.listen(3000, () => {
29
+ console.log("Upload API funcionando");
30
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "upload-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "multer": "^2.0.0"
9
+ }
10
+ }
@@ -0,0 +1,8 @@
1
+ export default function handler(req, res) {
2
+
3
+ res.status(200).json({
4
+ api: "Vercel API",
5
+ status: "online"
6
+ });
7
+
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "vercel-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "api/index.js",
6
+ "dependencies": {
7
+ "@vercel/node": "^3.0.0"
8
+ }
9
+ }
@@ -0,0 +1,28 @@
1
+ import express from "express";
2
+ import { WebSocketServer } from "ws";
3
+
4
+ const app = express();
5
+
6
+ const server = app.listen(3000, () => {
7
+ console.log("WebSocket API en puerto 3000");
8
+ });
9
+
10
+ const wss = new WebSocketServer({
11
+ server
12
+ });
13
+
14
+ wss.on("connection", (socket) => {
15
+
16
+ socket.send("Conectado al WebSocket");
17
+
18
+ socket.on("message", (message) => {
19
+
20
+ console.log("Mensaje:", message.toString());
21
+
22
+ socket.send(
23
+ "Recibido: " + message
24
+ );
25
+
26
+ });
27
+
28
+ });
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "websocket-api",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "express": "^5.0.0",
8
+ "ws": "^8.0.0"
9
+ }
10
+ }
@@ -0,0 +1,17 @@
1
+ export default {
2
+ async fetch(request) {
3
+
4
+ return new Response(
5
+ JSON.stringify({
6
+ api: "Cloudflare Workers API",
7
+ status: "online"
8
+ }),
9
+ {
10
+ headers: {
11
+ "Content-Type": "application/json"
12
+ }
13
+ }
14
+ );
15
+
16
+ }
17
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "workers-api",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "type": "module",
6
+ "dependencies": {}
7
+ }