Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
yangbo08 committed Mar 2, 2023
1 parent 7a346b1 commit a280050
Show file tree
Hide file tree
Showing 125 changed files with 22,189 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TENCENT_SECRET_ID=123
TENCENT_SECRET_KEY=123

# please change <appid> to your real appid
STATIC_URL=https://nuxtjs-demo-<appid>.cos.ap-guangzhou.myqcloud.com
91 changes: 91 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
/logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock
sw.*

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://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/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# Nuxt generate
dist

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless

# IDE / Editor
.idea

# Service worker
sw.*

# macOS
.DS_Store

# Vim swap files
*.swp
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": []
}
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# content
blog content
1 change: 1 addition & 0 deletions _config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"platformStage":"prod","accessKey":"AKIDc50Ex3N3c5kTl113gy6sOWiDD7ff0XyY%3AzJ8EHzUEU61K64PRtl57cCAjTcl6K1iX%3A41def7c179ac65a2fe5d8a82d344956c52bc3dcd20001","devMode":false,"orgName":"1256345838","stageName":"prod","appName":"yangboblog","instanceName":"nuxtjs-lOhsCPjJT","componentName":"nuxtjs","componentVersion":"1.0.8","srcHandler":"./_shims/handler.handler"}
48 changes: 48 additions & 0 deletions _shims/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
try {
require('tencent-component-monitor')
} catch (e) {
console.log(e)
}
const fs = require('fs')
const path = require('path')
const { createServer, proxy } = require('tencent-serverless-http')

let app
let server

module.exports.handler = async (event, context) => {
const userSls = path.join(__dirname, '..', process.env.SLS_ENTRY_FILE)
if (fs.existsSync(userSls)) {
// eslint-disable-next-line
console.log(`Using user custom entry file ${process.env.SLS_ENTRY_FILE}`)
app = await require(userSls)(true)
} else {
app = await require('./sls')(false)
}

// attach event and context to request
try {
app.request.__SLS_EVENT__ = event
app.request.__SLS_CONTEXT__ = context
} catch (e) {
// no op
}

// provide sls intialize hooks
if (app.slsInitialize && typeof app.slsInitialize === 'function') {
await app.slsInitialize()
}

if (!server) {
server = createServer(
app.callback && typeof app.callback === 'function' ? app.callback() : app,
null,
app.binaryTypes || []
)
}

context.callbackWaitsForEmptyEventLoop = app.callbackWaitsForEmptyEventLoop === true

const result = await proxy(server, event, context, 'PROMISE')
return result.promise
}
7 changes: 7 additions & 0 deletions _shims/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": {
"express": "^4.17.1",
"tencent-component-monitor": "^1.1.0",
"tencent-serverless-http": "^1.3.1"
}
}
28 changes: 28 additions & 0 deletions _shims/sls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const express = require('express')
const { loadNuxt } = require('nuxt')

async function createServer() {
// not report route for custom monitor
const noReportRoutes = ['/_nuxt', '/static', '/favicon.ico']

const server = express()
const nuxt = await loadNuxt('start')

server.all('*', (req, res, next) => {
noReportRoutes.forEach((route) => {
if (req.path.indexOf(route) === 0) {
req.__SLS_NO_REPORT__ = true
}
})
return nuxt.render(req, res, next)
})

// define binary type for response
// if includes, will return base64 encoded, very useful for images
server.binaryTypes = ['*/*']

// 返回 server
return server
}

module.exports = createServer
Loading

0 comments on commit a280050

Please sign in to comment.