{"id":23160927,"url":"https://github.com/sectly/sectserver","last_synced_at":"2025-04-04T19:27:55.302Z","repository":{"id":144667738,"uuid":"553199490","full_name":"Sectly/sectserver","owner":"Sectly","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-19T07:44:12.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T00:47:52.842Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sectly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-17T21:50:22.000Z","updated_at":"2022-10-19T07:40:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"ad64283c-5f18-46b6-97a9-6dc8ebcc601b","html_url":"https://github.com/Sectly/sectserver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sectly%2Fsectserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sectly%2Fsectserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sectly%2Fsectserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sectly%2Fsectserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sectly","download_url":"https://codeload.github.com/Sectly/sectserver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247236853,"owners_count":20906203,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-17T23:12:47.348Z","updated_at":"2025-04-04T19:27:55.297Z","avatar_url":"https://github.com/Sectly.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SectServer\r\n## An easy to use, fast and simple web framework for node.js with built-in template engine.\r\n\r\n`npm i sectserver`\r\n\r\n```javascript\r\nconst sectserver = require(\"sectserver\")\r\n\r\nvar app = sectserver();\r\n\r\napp.set('static dir', __dirname + '/public');\r\napp.set('views dir', __dirname + '/views');\r\n\r\napp.add({\r\n  url: '/',\r\n  handler: (req, res) =\u003e {\r\n    res.send('Hello, World!');\r\n  }\r\n})\r\n\r\napp.listen(3000);\r\n```\r\n\r\n# Example:\r\n\r\n```javascript\r\nconst sectserver = require(\"sectserver\")\r\n\r\nvar app = sectserver();\r\n\r\napp.set('static dir', __dirname + '/public');\r\napp.set('views dir', __dirname + '/views');\r\n\r\napp.add({\r\n  url: '/',\r\n  handler: (req, res) =\u003e { // \u003e /\r\n    res.render('Hello {globe}, My Name Is: {cool_name}!', {globe: `World`, cool_name: `SectServer`}); // Default Render Engine: SectPlating, See Guide To Change The Default.\r\n  }\r\n})\r\n\r\napp.add({ // :one = required, :one? = optional\r\n  url: '/test/:one?', // \u003e /test/world?two=SectServer\r\n  handler: (req, res) =\u003e {\r\n    res.render('Hello {one}, My Name Is: {two}!', {one: `${req.params.one}`, two: `${req.query.two}`});\r\n  }\r\n})\r\n\r\napp.add({\r\n  url: '/body', // \u003e /body\r\n  handler: (req, res) =\u003e {\r\n    res.json(`${JSON.stringify(req.body)}`);\r\n  }\r\n})\r\n\r\napp.add({\r\n  url: '/hi', // \u003e /hi\r\n  handler: (req, res) =\u003e {\r\n    res.send('Hello!');\r\n  }\r\n})\r\n\r\napp.add({\r\n  url: '/end', // \u003e /end\r\n  handler: (req, res) =\u003e {\r\n    res.end('The End!');\r\n  }\r\n})\r\n\r\napp.listen(8080);\r\n```\r\n\r\n# Guide:\r\n\r\nAfter you install the module, require it:\r\n```javascript\r\nconst sectserver = require('sectserver');\r\n```\r\ninitialize your app:\r\n```javascript\r\nlet app = sectserver();\r\n```\r\n\r\nIf you want, change the default configs:\r\n```javascript\r\napp.set('template', 'pug') /* view engine, see: https://www.npmjs.com/package/consolidate#supported-template-engines for a list of supported view engines | view engine defaults to: sectplating */\r\n.set('static dir', './public') /* static content directory (.css, .js, .json...)*/\r\n.set('views dir', './views'); /* views directory ( .pug, .haml, .html) */\r\napp.locals.foo = 'bar'; /* app.locals is an object that you can use (and call) it everywhere (middlewares, routers, renders...)*/\r\n```\r\nNow, you can add the middlewares you want\r\n```javascript\r\napp.add(compress()) /* data compress*/\r\n.add(favicon('./public/favicon.ico')) /* serve favicon and cache it*/\r\n.add(app.serveStatic('./public')) /* serve static content */\r\n.add(bodyParser.json()) /* data parser to req.body */\r\n.add(bodyParser.urlencoded({ extended: true })) /* same above */\r\n.add(cookieParser()) /* cookies parser to req.cookies */\r\n```\r\nyou can set routers for a path (or all)  and a method through the 'app.add' method.\r\n\r\n| Param | Object |\r\n|-----|---------|\r\n| req | Request. |\r\n| res | Response. |\r\n| next | Next middleware to call. |\r\n\r\n```javascript\r\napp.add(\r\n    (req,res,next) =\u003e {\r\n        res.render(\"index\", { title: 'My Title Page'});\r\n    }\r\n);\r\n```\r\n##Response\r\ninstance of http.ServerResponse.\r\n```javascript\r\nres.send('foo'); /* =\u003e send 'foo' */\r\nres.status(404); // response status is 404\r\nres.status(404).send('Not Found'); /* =\u003e send error 404 and 'Not Found' */\r\nres.sendStatus(404); /* =\u003e same above */\r\nres.json({'foo': 'bar'}) /* =\u003e send '{'foo':'bar'}'*/\r\nres.sendFile('/test.json') /* =\u003e send the content of file /public/test.json (or your static dir)*/\r\nres.render('index',{foo: 'bar',bar: 'foo'}) /* =\u003e send the view index.pug (default, or your views engine)*/\r\nres.redirect('/foo') /* =\u003e redirect users to /foo */\r\nres.locals /* =\u003e is similar to app.locals but only lives in current request (you can refresh it inn each request through middlewares) */\r\n```\r\n\r\n##Router\r\nIts a handler for your paths. You can to nest routers on the app.\r\n```javascript\r\nlet router = app.Router();\r\n\r\nrouter.add({\r\n        url: '/path', // \u003e /path\r\n        method: 'GET',\r\n        handler: (req,res,next) =\u003e { /* anything */}\r\n    })\r\n    .add({\r\n        url: '/path', // \u003e /path\r\n        method: 'POST',\r\n        handler: (req,res,next) =\u003e { /* anything */}\r\n    })\r\n    .add({\r\n        url: '/path', // \u003e /path\r\n        method: 'PUT',\r\n        handler: (req,res,next) =\u003e { /* anything */}\r\n    })\r\n    .add({\r\n        url: '/path', // \u003e /path\r\n        method: 'DELETE',\r\n        handler: (req,res,next) =\u003e { /* anything */}\r\n    })\r\n    .add({\r\n        url: '/path', // \u003e /path\r\n        method: 'PUT',\r\n        handler: (req,res,next) =\u003e { /* anything */}\r\n    })\r\n    .add({\r\n        url: '/user/:id', // \u003e /user/48\r\n        handler: (req,res,next) =\u003e { /* req.params.id */}\r\n    })\r\n    .add({\r\n        url: '/asset/', // \u003e /asset?name=logo.png\u0026from=images\r\n        handler: (req,res,next) =\u003e { /* req.query.name, req.query.from */}\r\n    })\r\n\r\n/* incorpore to your app */\r\napp.add({\r\n    url: '/foo',\r\n    handler: router\r\n    })\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsectly%2Fsectserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsectly%2Fsectserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsectly%2Fsectserver/lists"}