mirror of
https://github.com/filiprojek/nork.git
synced 2025-02-20 01:22:58 +01:00
v1 done
This commit is contained in:
106
src/skeletons/express-ts/.gitignore
vendored
106
src/skeletons/express-ts/.gitignore
vendored
@@ -1,3 +1,107 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
package-lock.json
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and *not* Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# package lock file
|
||||
package-lock.json
|
3
src/skeletons/express-ts/norkconfig.json
Normal file
3
src/skeletons/express-ts/norkconfig.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"lang": "ts"
|
||||
}
|
@@ -13,7 +13,7 @@
|
||||
"build": "npm-run-all clean tsc copy-assets"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Filip Rojek",
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
@@ -21,7 +21,8 @@
|
||||
"ejs": "^3.1.6",
|
||||
"express": "^4.17.1",
|
||||
"mongoose": "^5.12.3",
|
||||
"morgan": "^1.10.0"
|
||||
"morgan": "^1.10.0",
|
||||
"fs-extra": "^10.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cors": "^2.8.10",
|
||||
@@ -33,7 +34,6 @@
|
||||
"@types/morgan": "^1.9.2",
|
||||
"@types/node": "^14.14.41",
|
||||
"@types/shelljs": "^0.8.9",
|
||||
"fs-extra": "^10.0.0",
|
||||
"jest": "^27.0.6",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"rimraf": "^3.0.2",
|
||||
|
@@ -1,43 +1,43 @@
|
||||
import express from "express";
|
||||
import morgan from "morgan";
|
||||
import mongoose from "mongoose";
|
||||
import path from "path";
|
||||
import cors from "cors";
|
||||
import express from 'express'
|
||||
import morgan from 'morgan'
|
||||
import mongoose from 'mongoose'
|
||||
import path from 'path'
|
||||
import cors from 'cors'
|
||||
|
||||
const config = require("./utils/environment");
|
||||
const routes = require("./routes");
|
||||
const middlewares = require("./middlewares");
|
||||
const config = require('./utils/environment')
|
||||
const routes = require('./routes')
|
||||
const middlewares = require('./middlewares')
|
||||
|
||||
const port: Number = config.APP_PORT;
|
||||
const app = express();
|
||||
const port: Number = config.APP_PORT || 8080
|
||||
const app = express()
|
||||
|
||||
// MongoDB
|
||||
const dbURI: string = config.DB_URI;
|
||||
const dbURI: string = config.DB_URI
|
||||
mongoose
|
||||
.connect(dbURI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
useCreateIndex: true,
|
||||
})
|
||||
.then((result) => {
|
||||
console.log("connected to db");
|
||||
app.listen(port, () => {
|
||||
console.log(`Server is listening on http://localhost:${port}`);
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
.connect(dbURI, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
useCreateIndex: true,
|
||||
})
|
||||
.then(result => {
|
||||
console.log('connected to db')
|
||||
app.listen(port, () => {
|
||||
console.log(`Server is listening on http://localhost:${port}`)
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
// Middlewares
|
||||
app.use(middlewares);
|
||||
app.set("view engine", "ejs");
|
||||
app.set("views", path.join(__dirname, "views"));
|
||||
app.use(cors());
|
||||
app.use(morgan("dev"));
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(express.json());
|
||||
app.use(express.static(path.join(__dirname, "public")));
|
||||
app.use(middlewares)
|
||||
app.set('view engine', 'ejs')
|
||||
app.set('views', path.join(__dirname, 'views'))
|
||||
app.use(cors())
|
||||
app.use(morgan('dev'))
|
||||
app.use(express.urlencoded({ extended: true }))
|
||||
app.use(express.json())
|
||||
app.use(express.static(path.join(__dirname, 'public')))
|
||||
|
||||
// Routes
|
||||
app.use(routes);
|
||||
app.use(routes)
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import { Request, Response } from "express";
|
||||
import { Request, Response } from 'express'
|
||||
|
||||
const root_get = (req: Request, res: Response) => {
|
||||
res.render("home");
|
||||
return true;
|
||||
};
|
||||
res.render('home')
|
||||
return true
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
root_get,
|
||||
};
|
||||
root_get,
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { Router } from "express";
|
||||
const sayHiMiddleware = require("./sayHiMiddleware");
|
||||
import { Router } from 'express'
|
||||
const sayHiMiddleware = require('./sayHiMiddleware')
|
||||
|
||||
const router = Router();
|
||||
const router = Router()
|
||||
|
||||
router.use(sayHiMiddleware);
|
||||
router.use(sayHiMiddleware)
|
||||
|
||||
module.exports = router;
|
||||
module.exports = router
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { Router, Request, Response, NextFunction } from "express";
|
||||
import { Router, Request, Response, NextFunction } from 'express'
|
||||
|
||||
const router = Router();
|
||||
const router = Router()
|
||||
|
||||
router.use((req: Request, res: Response, next: NextFunction) => {
|
||||
console.log("Hi :)");
|
||||
console.log('Hi :)')
|
||||
|
||||
next();
|
||||
});
|
||||
next()
|
||||
})
|
||||
|
||||
module.exports = router;
|
||||
module.exports = router
|
||||
|
@@ -1,4 +1,4 @@
|
||||
const { Router } = require('express')
|
||||
import { Router } from 'express'
|
||||
const rootController = require('../controllers/rootController')
|
||||
|
||||
const router = Router()
|
||||
|
@@ -1,9 +1,9 @@
|
||||
const { getReq, getRes } = require("./modules/reqRes.module.js");
|
||||
const { root_get } = require("../controllers/rootController.ts");
|
||||
const { getReq, getRes } = require('./modules/reqRes.module.js')
|
||||
const { root_get } = require('../controllers/rootController.ts')
|
||||
|
||||
test("Home page render test", () => {
|
||||
const req = getReq();
|
||||
const res = getRes();
|
||||
test('Home page render test', () => {
|
||||
const req = getReq()
|
||||
const res = getRes()
|
||||
|
||||
expect(root_get(req, res)).toBe(true)
|
||||
});
|
||||
expect(root_get(req, res)).toBe(true)
|
||||
})
|
||||
|
@@ -1,16 +1,16 @@
|
||||
module.exports.getReq = () => {
|
||||
const req = {};
|
||||
req.body = {};
|
||||
return req;
|
||||
};
|
||||
const req = {}
|
||||
req.body = {}
|
||||
return req
|
||||
}
|
||||
|
||||
module.exports.getRes = () => {
|
||||
const res = {};
|
||||
res.locals = {};
|
||||
res.status = () => res;
|
||||
res.json = () => res;
|
||||
res.send = () => res;
|
||||
res.render = () => res;
|
||||
const res = {}
|
||||
res.locals = {}
|
||||
res.status = () => res
|
||||
res.json = () => res
|
||||
res.send = () => res
|
||||
res.render = () => res
|
||||
|
||||
return res;
|
||||
};
|
||||
return res
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import * as shell from "shelljs";
|
||||
import * as shell from 'shelljs'
|
||||
|
||||
// Copy all the view templates
|
||||
shell.cp("-R", "src/views", "dist/");
|
||||
shell.cp("-R", "src/public", "dist/");
|
||||
shell.cp("-u", "src/.env", "dist/");
|
||||
shell.cp('-R', 'src/views', 'dist/')
|
||||
shell.cp('-R', 'src/public', 'dist/')
|
||||
shell.cp('-u', 'src/.env', 'dist/')
|
||||
|
@@ -2,6 +2,6 @@ import path from 'path'
|
||||
require('dotenv').config({ path: path.join(__dirname, '../.env') })
|
||||
|
||||
module.exports = {
|
||||
APP_PORT: process.env.APP_PORT,
|
||||
DB_URI: process.env.DB_URI
|
||||
}
|
||||
APP_PORT: process.env.APP_PORT,
|
||||
DB_URI: process.env.DB_URI,
|
||||
}
|
||||
|
Reference in New Issue
Block a user